-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsplash_screen.dart
47 lines (42 loc) · 1.2 KB
/
splash_screen.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import 'dart:developer';
import 'package:demo_flutter/home_screen.dart';
import 'package:demo_flutter/login_screen.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
class SplashScreen extends StatefulWidget {
@override
_SplashScreen createState() {
return _SplashScreen();
}
}
class _SplashScreen extends State<SplashScreen> {
@override
initState() {
super.initState();
Future.delayed(Duration(seconds: 5));
checkAuthentication();
}
checkAuthentication() async {
log("Check Authentication");
SharedPreferences pref = await SharedPreferences.getInstance();
Navigator.pushReplacement(
context,
new MaterialPageRoute(
builder: (BuildContext buildContext) =>
pref.getBool("is_login") != null && pref.getBool("is_login")
? HomeScreen()
: LoginScreen()));
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: null,
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[CircularProgressIndicator()],
),
),
);
}
}