You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

77 lines
2.4 KiB

import 'dart:io';
import 'package:dating_touchme_app/config/env_config.dart';
import 'package:dating_touchme_app/network/network_service.dart';
import 'package:dating_touchme_app/pages/main_page.dart';
import 'package:dating_touchme_app/pages/mine/login_page.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);
// 初始化全局依赖
final networkService = NetworkService();
Get.put(networkService);
Get.put(networkService.userApi);
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
],
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<String>('token');
// 如果token为空,显示登录页面,否则显示主页
return token == null || token.isEmpty ? LoginPage() : MainPage();
}
}