-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmain.dart
65 lines (56 loc) · 1.42 KB
/
main.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import 'package:tiket/Helpers/helper.dart';
import 'package:tiket/Helpers/widget_helper.dart';
import 'package:tiket/adminMain.dart';
import 'package:flutter/material.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:tiket/Pages/loginPage.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
bool _isLoggedIn = false;
bool _isLoading = true;
@override
void initState() {
_checkIfLoggedIn();
super.initState();
setState(() {
_isLoading=true;
});
}
void _checkIfLoggedIn() async {
// check if token is there
SharedPreferences localStorage = await SharedPreferences.getInstance();
var token = localStorage.getString('api_token');
if(token!= null){
setState(() {
_isLoggedIn = true;
});
}
setState(() {
_isLoading=false;
});
}
@override
Widget build(BuildContext context) {
final textTheme = Theme.of(context).textTheme;
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: THEME_COLOR,
),
/*debugShowCheckedModeBanner: false,*/
home:
_isLoading ? loadingWidget(context)
:
(_isLoggedIn ?
AdminMain()
:
LoginPage()
),
);
}
}