Autologin implemented
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:maggs_victory_voyage/services/db_helper.dart';
|
||||
|
||||
import 'login_page.dart';
|
||||
|
||||
@@ -10,8 +11,38 @@ class SplashPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _SplashPageState extends State<SplashPage> {
|
||||
late final Future<bool> loginFuture;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
loginFuture = DbHelper.autoLogin();
|
||||
DbHelper.authEventStream.listen((event) => setState(() {}));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return const LoginPage();
|
||||
return Scaffold(
|
||||
body: FutureBuilder(
|
||||
future: loginFuture,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.hasData) {
|
||||
if (DbHelper.currentUser == null) {
|
||||
return const LoginPage();
|
||||
}
|
||||
return const Column(
|
||||
children: [
|
||||
Text('Logged in!'),
|
||||
TextButton(
|
||||
onPressed: DbHelper.logout,
|
||||
child: Text('Log out'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user