From 71707bd1c0ea5a417d20d05c9039de3a1f40ef14 Mon Sep 17 00:00:00 2001 From: juan Date: Wed, 23 Jul 2025 10:30:07 -0400 Subject: [PATCH] fix for composing widget --- lib/login.dart | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/lib/login.dart b/lib/login.dart index ca2c3f9..a03f4d1 100644 --- a/lib/login.dart +++ b/lib/login.dart @@ -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 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 { @override void initState() { super.initState(); - _checkLoginStatus(); + WidgetsBinding.instance.addPostFrameCallback((_) { + _checkLoginStatus(); + }); } Future _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 { 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 { final _formKey = GlobalKey(); Future setIp(String ip) async { + //this is not done :sob: :skull: // _configManager.setField("api_addr", ip); return false; }