173 lines
5.9 KiB
Dart
173 lines
5.9 KiB
Dart
import 'package:ef/ef.dart';
|
||
import 'package:flutter/material.dart';
|
||
import 'package:flutter/services.dart';
|
||
import 'package:get_storage/get_storage.dart';
|
||
import 'package:vbvs_app/common/util/FitTool.dart';
|
||
import 'package:vbvs_app/controller/device/blueteeth_bind_controller.dart';
|
||
import 'package:vbvs_app/controller/login/login_controller.dart';
|
||
import 'package:vbvs_app/controller/main_bottom/global_controller.dart';
|
||
import 'package:vbvs_app/controller/main_bottom/main_page_controller.dart';
|
||
import 'package:vbvs_app/controller/person/person_controller.dart';
|
||
import 'package:vbvs_app/controller/theme_controller/ThemeController.dart';
|
||
import 'package:vbvs_app/controller/time/countdown_controller.dart';
|
||
import 'package:vbvs_app/language/AppLanguage.dart';
|
||
import 'package:vbvs_app/model/CustomThemeColor.dart';
|
||
import 'package:vbvs_app/model/user_data.dart';
|
||
import 'controller/user_info_controller.dart';
|
||
import 'routers/routers.dart';
|
||
|
||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||
import 'package:syncfusion_localizations/syncfusion_localizations.dart';
|
||
|
||
Future<void> main() async {
|
||
WidgetsFlutterBinding.ensureInitialized();
|
||
await AppLanguage().loadLanguage("zh_CN");
|
||
WidgetsFlutterBinding.ensureInitialized();
|
||
|
||
// ApiService.init();
|
||
// await GetStorage.init();
|
||
// 初始化登录
|
||
await initLogin();
|
||
await initLog();
|
||
// 检查网络
|
||
// Checknetwork.checkNetwork();
|
||
// 微信开放平台注册
|
||
// initWX();
|
||
// // 初始化 flutter_xupdate android app 更新
|
||
// initXUpdate();
|
||
|
||
WidgetsFlutterBinding.ensureInitialized();
|
||
SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp])
|
||
.then((_) {
|
||
runApp(MyApp());
|
||
});
|
||
|
||
// runApp(const MyApp());
|
||
}
|
||
|
||
initLog() {
|
||
|
||
}
|
||
|
||
Future<void> initLogin() async {
|
||
// 初始化控制器
|
||
Get.put(UserInfoController());
|
||
// Get.put(SettingController());
|
||
|
||
// 获取设备信息,需要用户点击确认隐私协议与用户协议选择框时才能获取
|
||
// Deviceconfig.initPlatformState();
|
||
// 获取app版本号
|
||
// SettingController settingController = Get.find();
|
||
// settingController.model.appVersion = await Deviceconfig.getAppVersion();
|
||
|
||
final box = GetStorage();
|
||
UserInfoController userInfoController = Get.find();
|
||
String? token = box.read('token');
|
||
// print('Token: $token');
|
||
Map<String, dynamic>? userMap = box.read('user');
|
||
if (userMap != null) {
|
||
UserModel user = UserModel.fromJson(userMap);
|
||
userInfoController.model.user = user;
|
||
}
|
||
if (token != null) {
|
||
// userInfoController.model.login = 1;
|
||
//根据token去请求
|
||
// await userInfoController.autoLogin(token);
|
||
} else {
|
||
// 如果没有 token,则将用户标记为未登录
|
||
userInfoController.model.login = 0;
|
||
}
|
||
}
|
||
|
||
// 初始化微信开放平台注册
|
||
// Future<void> initWX() async {
|
||
// Fluwx fluwx = Fluwx();
|
||
// fluwx.registerApi(
|
||
// //请填写自己的微信appid
|
||
// appId: "wx929c548fea6af9c7",
|
||
// doOnAndroid: true,
|
||
// doOnIOS: true,
|
||
// universalLink: "https://zhmht.swes.com.cn/app/");
|
||
// }
|
||
|
||
// // 初始化 flutter_xupdate android app 更新
|
||
// Future<void> initXUpdate() async {
|
||
// if (Platform.isAndroid) {
|
||
// FlutterXUpdate.init(
|
||
// // 是否输出日志
|
||
// debug: true,
|
||
// // 是否使用post请求
|
||
// isPost: true,
|
||
// // post请求是否是上传json
|
||
// isPostJson: false,
|
||
// // 请求响应超时时间
|
||
// timeout: 25000,
|
||
// // 是否开启自动模式
|
||
// isWifiOnly: false,
|
||
// // 是否开启自动模式
|
||
// isAutoMode: false,
|
||
// // 需要设置的公共参数
|
||
// supportSilentInstall: false,
|
||
// // 在下载过程中,如果点击了取消的话,是否弹出切换下载方式的重试提示弹窗
|
||
// enableRetry: false)
|
||
// .then((value) {
|
||
// print('初始化成功: $value');
|
||
// }).catchError((error) {
|
||
// print(error);
|
||
// });
|
||
|
||
// FlutterXUpdate.setUpdateHandler(onUpdateError: (message) async {
|
||
// print('onUpdateError: $message');
|
||
// });
|
||
// }
|
||
// }
|
||
|
||
class MyApp extends StatelessWidget {
|
||
MyApp({super.key});
|
||
final ThemeController themeController = Get.put(ThemeController());
|
||
|
||
// This widget is the root of your application.
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
themeController.changeTheme(CustomThemeColor.dark);
|
||
UserInfoController userInfoController = Get.find();
|
||
return LayoutBuilder(builder: (contxt, cons) {
|
||
double width = cons.maxWidth;
|
||
double height = cons.maxHeight;
|
||
if (width < 1) {
|
||
return Container();
|
||
}
|
||
FitTool.init(width < height ? width : height);
|
||
return GetMaterialApp(
|
||
translations: AppLanguage(),
|
||
locale: const Locale("zh", "CN"),
|
||
fallbackLocale: const Locale("zh", "CN"),
|
||
localizationsDelegates: [
|
||
GlobalMaterialLocalizations.delegate,
|
||
GlobalWidgetsLocalizations.delegate,
|
||
GlobalCupertinoLocalizations.delegate,
|
||
SfGlobalLocalizations.delegate,
|
||
],
|
||
supportedLocales: [
|
||
const Locale('zh', 'CN'), // 中文
|
||
// 其他支持的语言
|
||
],
|
||
debugShowCheckedModeBanner: false,
|
||
title: '',
|
||
theme: themeController.currentTheme,
|
||
// home: const MyHomePage(title: '智慧眠花糖 Home Page'),
|
||
initialRoute: "/mianPageBottomChange",
|
||
onGenerateRoute: onGenerateRoute,
|
||
initialBinding: BindingsBuilder(() => [
|
||
Get.lazyPut(() => UserInfoController()),
|
||
Get.put(GlobalController()),
|
||
Get.lazyPut(() => MainPageController()),
|
||
Get.lazyPut(() => BlueteethBindController()),
|
||
Get.lazyPut(() => PersonController()),
|
||
Get.lazyPut(() => CountdownController()),
|
||
Get.lazyPut(() => LoginController()),
|
||
]));
|
||
});
|
||
}
|
||
}
|