main.dart 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter/services.dart';
  3. import 'package:flutter_localizations/flutter_localizations.dart';
  4. import 'package:flutter_screenutil/flutter_screenutil.dart';
  5. import 'package:flutter_tzh/base/YSTabBar.dart';
  6. import 'package:flutter_tzh/login/YSLogin.dart';
  7. import 'package:flutter_tzh/tool/YSLocalization.dart';
  8. import 'package:shared_preferences/shared_preferences.dart';
  9. void main() async{
  10. WidgetsFlutterBinding.ensureInitialized();
  11. SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light.copyWith(statusBarColor: Colors.transparent));
  12. SharedPreferences prefs = await SharedPreferences.getInstance();
  13. String? token = prefs.getString('token');
  14. bool isLogin = token==null?false:true;
  15. runApp(MyApp(isLogin: isLogin,));
  16. }
  17. class MyApp extends StatelessWidget {
  18. final bool isLogin;
  19. const MyApp({Key? key, required 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(375, 812),
  25. minTextAdapt: true,
  26. splitScreenMode: true,
  27. builder: (BuildContext context, Widget? child) {
  28. return MaterialApp(
  29. debugShowCheckedModeBanner: false,
  30. title: '碳中和',
  31. theme: ThemeData(
  32. primarySwatch: Colors.blue,
  33. ),
  34. localizationsDelegates: const [
  35. ZhCupertinoLocalizations.delegate,
  36. GlobalMaterialLocalizations.delegate,
  37. GlobalWidgetsLocalizations.delegate,
  38. GlobalCupertinoLocalizations.delegate,
  39. ],
  40. supportedLocales: const [
  41. Locale('zh', 'CH'),
  42. Locale('en', 'US'),
  43. ],
  44. home: isLogin?const YSTabBar():const YSLogin(),
  45. );
  46. },
  47. );
  48. }
  49. }