fix for composing widget

This commit is contained in:
Juan Marulanda De Los Rios 2025-07-23 10:30:07 -04:00
parent b961be3e8b
commit 71707bd1c0

View File

@ -1,15 +1,22 @@
import 'dart:convert';
// import 'package:crab_ui/api_service.dart';
import 'package:go_router/go_router.dart';
import 'api_service.dart';
import 'home_page.dart';
// import 'home_page.dart';
import 'package:flutter/material.dart';
// import 'package:flutter_widget_from_html/flutter_widget_from_html.dart';
import 'package:http/http.dart' as http;
// import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter/services.dart' show rootBundle;
class AuthService {
class AuthService extends ChangeNotifier {
Future<bool> isUserLoggedIn() async {
ApiService.ip = '192.168.2.38';
ApiService.port = '3001';
print("setted up");
return true;
try {
final response =
await http.get(Uri.http('localhost:6823', 'read-config'));
@ -83,6 +90,7 @@ class LoginPage extends StatefulWidget {
}
class SplashScreen extends StatefulWidget {
//entry point
@override
_SplashScreenState createState() => _SplashScreenState();
}
@ -92,19 +100,24 @@ class _SplashScreenState extends State<SplashScreen> {
@override
void initState() {
super.initState();
_checkLoginStatus();
WidgetsBinding.instance.addPostFrameCallback((_) {
_checkLoginStatus();
});
}
Future<void> _checkLoginStatus() async {
// SharedPreferences prefs = await SharedPreferences.getInstance();
// print(prefs);
// bool isLoggedIn = prefs.getBool('isLoggedIn') ?? false;
await Future.delayed(const Duration(seconds: 1));
bool isLoggedIn = await _authService.isUserLoggedIn();
print("is loogeed in $isLoggedIn");
print("is logged in $isLoggedIn");
if (isLoggedIn) {
Navigator.pushReplacementNamed(context, '/home');
context.go("/home");
// Navigator.pushReplacementNamed(context, '/home');
} else {
Navigator.pushReplacementNamed(context, '/login');
context.go("/login");
// Navigator.pushReplacementNamed(context, '/login');
}
}
@ -112,7 +125,7 @@ class _SplashScreenState extends State<SplashScreen> {
Widget build(BuildContext context) {
return Center(
child: Scaffold(
body: Center(child: CircularProgressIndicator()),
body: Center(child: CircularProgressIndicator()), //nothing happens
),
);
}
@ -132,6 +145,7 @@ class _LoginPageState extends State<LoginPage> {
final _formKey = GlobalKey<FormState>();
Future<bool> setIp(String ip) async {
//this is not done :sob: :skull:
// _configManager.setField("api_addr", ip);
return false;
}