import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_tzh/base/YSTabBar.dart'; import 'package:flutter_tzh/login/YSLogin.dart'; import 'package:flutter_tzh/tool/YSLocalization.dart'; import 'package:shared_preferences/shared_preferences.dart'; void main() async{ WidgetsFlutterBinding.ensureInitialized(); SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.light.copyWith(statusBarColor: Colors.transparent)); SharedPreferences prefs = await SharedPreferences.getInstance(); String? token = prefs.getString('token'); bool isLogin = token==null?false:true; runApp(MyApp(isLogin: isLogin,)); } class MyApp extends StatelessWidget { final bool isLogin; const MyApp({Key? key, required this.isLogin}) : super(key: key); // This widget is the root of your application. @override Widget build(BuildContext context) { return ScreenUtilInit( designSize: const Size(375, 812), minTextAdapt: true, splitScreenMode: true, builder: (BuildContext context, Widget? child) { return MaterialApp( debugShowCheckedModeBanner: false, title: '碳中和', theme: ThemeData( primarySwatch: Colors.blue, ), localizationsDelegates: const [ ZhCupertinoLocalizations.delegate, GlobalMaterialLocalizations.delegate, GlobalWidgetsLocalizations.delegate, GlobalCupertinoLocalizations.delegate, ], supportedLocales: const [ Locale('zh', 'CH'), Locale('en', 'US'), ], home: isLogin?const YSTabBar():const YSLogin(), ); }, ); } }