import 'dart:io'; import 'package:dating_touchme_app/config/env_config.dart'; import 'package:dating_touchme_app/controller/global.dart'; import 'package:dating_touchme_app/im/im_manager.dart'; import 'package:dating_touchme_app/network/network_service.dart'; import 'package:dating_touchme_app/pages/main/main_page.dart'; import 'package:dating_touchme_app/pages/mine/login_page.dart'; import 'package:dating_touchme_app/pages/mine/user_info_page.dart'; import 'package:dating_touchme_app/rtc/rtc_manager.dart'; 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_smart_dialog/flutter_smart_dialog.dart'; import 'package:get/get.dart'; import 'package:get_storage/get_storage.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); // 初始化GetStorage await GetStorage.init(); // 设置环境配置 - 根据是否为release模式 EnvConfig.setEnvironment(Environment.dev); await RTCManager.instance.initialize(appId: '4c2ea9dcb4c5440593a418df0fdd512d'); await IMManager.instance.initialize('1165251016193374#demo'); // 初始化全局依赖 final networkService = NetworkService(); Get.put(networkService); Get.put(networkService.userApi); Get.put(networkService.homeApi); SystemChrome.setSystemUIOverlayStyle( const SystemUiOverlayStyle( statusBarColor: Colors.transparent, statusBarIconBrightness: Brightness.dark, statusBarBrightness: Brightness.light, systemNavigationBarColor: Colors.white, systemNavigationBarIconBrightness: Brightness.dark, ), ); SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]); if (Platform.isIOS) { SystemChrome.setEnabledSystemUIMode( SystemUiMode.manual, overlays: [SystemUiOverlay.top], ); } runApp( GetMaterialApp( locale: Get.locale, // 使用GetX的locale supportedLocales: const [Locale('zh', 'CN')], /// 国际化配置 代理 localizationsDelegates: const [ GlobalMaterialLocalizations.delegate, GlobalWidgetsLocalizations.delegate, GlobalCupertinoLocalizations.delegate, // iOS ], theme: ThemeData( scaffoldBackgroundColor: Colors.white, // 设置导航栏样式 appBarTheme: AppBarTheme( systemOverlayStyle: SystemUiOverlayStyle( systemNavigationBarColor: Colors.white, systemNavigationBarIconBrightness: Brightness.light, ), ), ), builder: FlutterSmartDialog.init(), home: MyApp(), ), ); } class MyApp extends StatelessWidget { const MyApp({super.key}); // This widget is the root of your application. @override Widget build(BuildContext context) { ScreenUtil.init(context, designSize: const Size(375, 812)); // 判断token是否为空 final storage = GetStorage(); final token = storage.read('token'); // 如果token不为空,显示主页;如果token为空,显示登录页面 if (token != null && token.isNotEmpty) { GlobalData().userId = storage.read('userId'); return MainPage(); } else { return LoginPage(); } } }