import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; import 'package:flutter/services.dart'; import 'package:get/get.dart'; import 'package:flutter_app_update/flutter_app_update.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; // import 'controller/scence_map.dart'; import 'appbar/appbar.dart'; import 'login_in/connect/index.dart'; import 'login_in/connect/my_routes.dart'; import 'login_in/getx/index.dart'; import 'login_in/getx/real_data.dart'; import 'login_in/user/loginprefs.dart'; import 'screens/aimpoint_page.dart'; import 'screens/setting_page.dart'; Connect connect = Connect(); void main() async { WidgetsFlutterBinding.ensureInitialized(); SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []); //设置全屏 Get.put(RealController()); LoginPrefs loginPrefs = LoginPrefs(); String value = await loginPrefs.init(); // await 关键字必须用在异步方法中 await等待异步方法执行完毕 异步方法必须用变量接收 if ('ok' == value) { connect.init(); runApp(const EntryPage()); } } class EntryPage extends StatefulWidget { const EntryPage({super.key}); @override State createState() => _EntryPageState(); } class _EntryPageState extends State { @override void initState() { super.initState(); } @override Widget build(BuildContext context) { return ValueListenableBuilder( valueListenable: MyApp.isDarkMode, builder: (context, isDarkMode, child) { return MaterialApp( debugShowCheckedModeBanner: false, home: const MyApp(), initialRoute: "home", onGenerateRoute: onGenerateRoute, localizationsDelegates: GlobalMaterialLocalizations.delegates, supportedLocales: const [ Locale('en', ''), Locale('zh', ''), Locale('he', ''), Locale('es', ''), Locale('ru', ''), Locale('ko', ''), Locale('hi', ''), ], theme: isDarkMode ? ThemeData.dark() : ThemeData.light(), // home: child, ); }, child: const Text(""), ); } } TextStyle textStyle = const TextStyle(fontSize: 15); class MyApp extends StatefulWidget { const MyApp({super.key}); static ValueNotifier isDarkMode = ValueNotifier(false); @override State createState() => _MyAppState(); } //是否是竖屏,用于修改appbar 的高度 late bool isPortrait; class _MyAppState extends State { //当前底部导航栏索引 var _currentIndex = 1.obs; late double appBarHeight; var url = 'http://v5.rdc.pub/apk/'; ///Flutter侧处理升级对话框 ///[forcedUpgrade] 是否强制升级 _showUpdateDialog(bool forcedUpgrade, String version) { showDialog( context: context, barrierDismissible: !forcedUpgrade, builder: (BuildContext context) { return PopScope( child: AlertDialog( title: const Text('发现新版本'), content: Text( version, style: const TextStyle(fontSize: 20), ), actions: [ if (!forcedUpgrade) TextButton( child: const Text('稍后升级'), onPressed: () => Navigator.of(context).pop(), ), TextButton( child: const Text('升级'), onPressed: () { _appUpdate(); if (!forcedUpgrade) { Navigator.of(context).pop(); } }, ), ], ), ); }, ); } _appUpdate() { UpdateModel model = UpdateModel( "${url}app-release.apk", "app-release.apk", "ic_launcher", "", ); AzhonAppUpdate.update(model).then((value) => debugPrint('//////$value')); } bool comarableVersion(String version1, String version2) { List v1 = version1.split('.').map(int.parse).toList(); List v2 = version2.split('.').map(int.parse).toList(); bool result = true; for (int i = 0; i < 3; i++) { if (v1[i] > v2[i]) { result = true; break; } else if (v1[i] < v2[i]) { result = false; break; } } return result; } @override void initState() { GexRegister().registerDependencies(); super.initState(); SchedulerBinding.instance.addPostFrameCallback((_) async { // 当前版本 // PackageInfo packageInfo = await PackageInfo.fromPlatform(); // String version = packageInfo.version; // String packageName = packageInfo.packageName; // print("---$packageName,$version"); // var response = // await http.Client().get(Uri.parse("${url}output-metadata.json")); // Map json = jsonDecode(response.body); // String onLineVersion = json["elements"][0]["versionName"] ?? ""; // // 获取线上版本 // if (comarableVersion(version, onLineVersion) && // version != onLineVersion) { // //升级弹窗 // _showUpdateDialog(false, onLineVersion); // } // AzhonAppUpdate.listener((map) { // debugPrint(map['type']); // }); }); } final RealController controller1 = Get.find(); final List _pages = [ ScenceMap(), ScenceMap(), ScenceMap(), ScenceMap(), SettingPortrait() ]; @override Widget build(BuildContext context) { final size = MediaQuery.of(context).size; return OrientationBuilder(builder: ((context, orientation) { isPortrait = Orientation.portrait == orientation ? true : false; appBarHeight = Orientation.portrait == orientation ? 56.0 : 34.0; return Scaffold( resizeToAvoidBottomInset: false, drawerEdgeDragWidth: 0.0, // 禁止通过滑动打开drawer endDrawer: _currentIndex.value == 1 ? Drawer( width: size.width * .8, child: const AimPointer(), ) : null, appBar: PreferredSize( preferredSize: Size.fromHeight(appBarHeight), child: CustomAppBar(appBarHeight: 56, currentIndex: _currentIndex), ), body: OrientationBuilder( builder: (context, orientation) { if (!isPortrait) { return Row( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Expanded( child: _pages[_currentIndex.value], ), const VerticalDivider( width: 1, // 设置高度为1 thickness: 1, ), SizedBox( width: 48, child: SafeArea( child: LayoutBuilder(builder: (context, constraints) { // 根据屏幕宽度判断横屏或竖屏 // if (!isPortrait) { // // 横屏布局 return Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly, crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Column( children: [ IconButton( onPressed: () { setState(() { _currentIndex.value = 0; }); }, icon: const Icon( Icons.date_range_rounded), color: _currentIndex.value == 0 ? const Color.fromARGB( 255, 60, 95, 123) : Colors.grey, ), Align( alignment: Alignment.center, child: Text( '实时', style: TextStyle( fontSize: 12, color: _currentIndex.value == 0 ? const Color.fromARGB( 255, 60, 95, 123) : Colors.grey, ), ), ), ], ), const Divider( height: 1, // 设置高度为1 thickness: 1, ), // Column( children: [ IconButton( onPressed: () { setState(() { _currentIndex.value = 1; }); }, icon: const Icon(Icons.map_outlined), color: _currentIndex.value == 1 ? const Color.fromARGB( 255, 60, 95, 123) : Colors.grey, ), Align( alignment: Alignment.center, child: Text( '桩点', style: TextStyle( fontSize: 12, color: _currentIndex.value == 1 ? const Color.fromARGB( 255, 60, 95, 123) : Colors.grey, ), ), ), ], ), const Divider(), Column( children: [ IconButton( onPressed: () { setState(() { _currentIndex.value = 2; }); }, icon: const Icon(Icons.my_location_sharp), color: _currentIndex.value == 2 ? const Color.fromARGB( 255, 60, 95, 123) : Colors.grey, ), Align( alignment: Alignment.center, child: Text( '任务', style: TextStyle( fontSize: 12, color: _currentIndex.value == 2 ? const Color.fromARGB( 255, 60, 95, 123) : Colors.grey, ), ), ), ], ), const Divider(), Column( children: [ IconButton( onPressed: () { setState(() { _currentIndex.value = 3; }); }, icon: const Icon( Icons.table_chart_outlined), color: _currentIndex.value == 3 ? const Color.fromARGB( 255, 60, 95, 123) : Colors.grey, ), Align( alignment: Alignment.center, child: Text( '历史', style: TextStyle( fontSize: 12, color: _currentIndex.value == 3 ? const Color.fromARGB( 255, 60, 95, 123) : Colors.grey, ), ), ), ], ), const Divider(), Column( children: [ IconButton( onPressed: () { setState(() { _currentIndex.value = 4; }); }, icon: const Icon(Icons.settings), color: _currentIndex.value == 4 ? const Color.fromARGB( 255, 60, 95, 123) : Colors.grey, ), Align( alignment: Alignment.center, child: Text( '设置', style: TextStyle( fontSize: 12, color: _currentIndex.value == 4 ? const Color.fromARGB( 255, 60, 95, 123) : Colors.grey, ), ), ), ], ) ]); // }), ), ) ]); } // else { // 竖屏布局,保持原有底部导航栏样式 return Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Expanded( flex: 12, child: _pages[_currentIndex.value], ), // VerticalDivider(), Expanded( flex: 1, child: SizedBox( height: 58, child: BottomNavigationBar( type: BottomNavigationBarType.fixed, currentIndex: _currentIndex.value, onTap: (index) { setState(() { _currentIndex.value = index; }); }, items: const [ BottomNavigationBarItem( icon: Icon(Icons.date_range_rounded), label: "实时"), BottomNavigationBarItem( icon: Icon(Icons.map_outlined), label: "桩点"), BottomNavigationBarItem( icon: Icon(Icons.my_location_sharp), label: "对点"), BottomNavigationBarItem( icon: Icon(Icons.table_chart_outlined), label: "历史"), BottomNavigationBarItem( icon: Icon(Icons.settings), label: "设置"), ]), ), ) ]); } }, )); })); } }