main.dart 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_screenutil/flutter_screenutil.dart';
  3. import 'package:flutter_tracker/pages/login_page.dart';
  4. import 'package:shared_preferences/shared_preferences.dart';
  5. import 'index_page.dart';
  6. import 'model/config.dart';
  7. void main() async {
  8. WidgetsFlutterBinding.ensureInitialized();
  9. Config.initConfig();
  10. SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
  11. bool isLogin = sharedPreferences.getBool("isLogin");
  12. isLogin ??= false;
  13. runApp(MyApp(
  14. isLogin: isLogin,
  15. ));
  16. }
  17. class MyApp extends StatelessWidget {
  18. bool isLogin = false;
  19. MyApp({Key key, this.isLogin}) : super(key: key);
  20. // This widget is the root of your application.
  21. @override
  22. Widget build(BuildContext context) {
  23. return ScreenUtilInit(
  24. designSize: const Size(750, 1344),
  25. builder: () =>
  26. MaterialApp(
  27. title: '追踪者',
  28. theme: ThemeData(
  29. primarySwatch: Colors.blue,
  30. ),
  31. debugShowCheckedModeBanner: false,
  32. home: isLogin ? IndexPage() : LoginPage(),
  33. ),
  34. );
  35. }
  36. }