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