import 'package:cpnav/controllers/appcontroller.dart'; import 'package:cpnav/pages/task/task_page.dart'; import 'package:flutter/material.dart'; import 'package:flutter/scheduler.dart'; import 'package:flutter/services.dart'; import 'package:get/get.dart'; import 'package:scence_map/controllers/controller.dart'; import 'appbar.dart'; import 'pages/aim_point/aimpoint_controller.dart'; import 'pages/history/history_record.dart'; import 'pages/login/login_page.dart'; import 'pages/login/my_routes.dart'; import 'pages/pass_track/view.dart'; import 'pages/real/real_controller.dart'; import 'pages/dataAndDevice/controller.dart'; import 'pages/setting/child_pages/antenna/antenna_setting.dart'; import 'pages/setting/child_pages/connect/config/socket_setting.dart'; import 'pages/setting/setting_controller.dart'; import 'pages/setting/setting_page.dart'; import 'pages/task/taskcontroller.dart'; import 'service/user/loginprefs.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; import 'package:scence_map/controllers/plum_controller.dart'; import '../../controllers/gnss_controller.dart'; final AppController appcontroller = Get.put(AppController()); final GlobalKey scaffoldMessengerKey = GlobalKey(); // Connect connect = Connect(); SocketSetting socket = SocketSetting(); void main() async { WidgetsFlutterBinding.ensureInitialized(); SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []); //设置全屏 Get.put(SettingController()); Get.put(LoginPageController()); Get.put(AccountLoginController()); Get.put(PhoneLoginController()); Get.put(ScenceMapController()); Get.put(AimPointerController()); Get.put(RealController()); Get.put(RealDataController()); Get.put(PlumRealDataController()); LoginPrefs loginPrefs = LoginPrefs(); String value = await loginPrefs.init(); // await 关键字必须用在异步方法中 await等待异步方法执行完毕 异步方法必须用变量接收 if ('ok' == value) { socket.connect(); // loginPrefs.removeToken(); //注释掉即能实现短时间二次登录不需要再重新登录 runApp(const MyApp()); } } class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget build(BuildContext context) { return Obx(() { return MaterialApp( scaffoldMessengerKey: scaffoldMessengerKey, // title: 'Flutter Demo', theme: appcontroller.isDarkMode.value ? ThemeData.dark() : ThemeData.light(), debugShowCheckedModeBanner: false, onGenerateRoute: (settings) { String str = routeBeforeHook(settings); Widget page = routes[str]!; return MaterialPageRoute(builder: (BuildContext context) => page); }, home: const MyHomePage(), initialRoute: "home", localizationsDelegates: GlobalMaterialLocalizations.delegates, supportedLocales: const [ Locale('zh', ''), Locale('en', ''), ], ); }); } } class MyHomePage extends StatefulWidget { const MyHomePage({ super.key, }); @override State createState() => _MyHomePageState(); } class _MyHomePageState extends State { late bool isPortrait; late double appBarHeight = 44.0; bool isInitialized = false; @override void initState() { super.initState(); SettingController settingController = Get.put(SettingController()); SchedulerBinding.instance.addPostFrameCallback((_) async { settingController.getDeviceId(context); await loadData(settingController); setState(() { isInitialized = settingController.isInitialized; Get.put(PlumDataController()); Get.put(AntennaController()); Get.put(TaskController()); Get.put(GnssController()); }); }); } @override Widget build(BuildContext context) { if (!isInitialized) { return const Scaffold( body: Center( child: CircularProgressIndicator(), ), ); } final List pages = [ // const Real(), PassTackAndDevice(), const TaskManagePage(), const HistoryRecord(), const SettingPortrait() ]; return Scaffold( resizeToAvoidBottomInset: false, drawerEdgeDragWidth: 0.0, // 禁止通过滑动打开drawer appBar: PreferredSize( preferredSize: Size.fromHeight(appBarHeight), child: CustomAppBar( appBarHeight: 66, currentIndex: appcontroller.currentIndex, ), ), body: OrientationBuilder( builder: (context, orientation) { // final size = MediaQuery.of(context).size; appBarHeight = Orientation.portrait == orientation ? 66.0 : 44.0; isPortrait = Orientation.portrait == orientation ? true : false; return Obx(() { appcontroller.currentIndex.value; if (!isPortrait) { return Row( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Expanded( child: pages[appcontroller.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: [ // buildIconButton( // context: context, // index: 0, // icon: Icons.date_range_rounded, // label: '实时', // ), // const Divider(), buildIconButton( context: context, index: 0, icon: Icons.map_outlined, label: '桩点', ), const Divider(), buildIconButton( context: context, index: 1, icon: Icons.my_location_sharp, label: '任务', ), const Divider(), buildIconButton( context: context, index: 2, icon: Icons.table_chart_outlined, label: '历史', ), const Divider(), buildIconButton( context: context, index: 3, icon: Icons.settings, label: '设置', ), ]); // }), ), ) ]); } // else { // 竖屏布局,保持原有底部导航栏样式 return Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Expanded( flex: 12, child: pages[appcontroller.currentIndex.value], ), // VerticalDivider(), Expanded( flex: 1, child: SizedBox( height: 48, child: BottomNavigationBar( type: BottomNavigationBarType.fixed, currentIndex: appcontroller.currentIndex.value, onTap: (index) { setState(() { appcontroller.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: "设置"), ]), ), ) ]); } }); }, ), ); } Widget buildIconButton({ required BuildContext context, required int index, required IconData icon, required String label, }) { return InkWell( onTap: () { setState(() { appcontroller.currentIndex.value = index; }); }, child: Column( children: [ Icon( (icon), color: appcontroller.currentIndex.value == index ? const Color.fromARGB(255, 60, 95, 123) : Colors.grey, ), Align( alignment: Alignment.center, child: Text( label, style: TextStyle( fontSize: 12, color: appcontroller.currentIndex.value == index ? const Color.fromARGB(255, 60, 95, 123) : Colors.grey, ), ), ), ], ), ); } }