pile_nav_new/lib/main.dart

342 lines
15 KiB
Dart
Raw Normal View History

2024-08-30 17:57:33 +08:00
import 'package:cpnav/controllers/appcontroller.dart';
2024-08-26 18:58:33 +08:00
import 'package:cpnav/controllers/gnss_Controller.dart';
2024-08-30 17:57:33 +08:00
import 'package:cpnav/pages/setting/child_pages/antenna/antenna_setting.dart';
2024-09-03 18:05:49 +08:00
import 'package:cpnav/pages/task/task_page.dart';
2024-08-18 22:42:37 +08:00
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
2024-08-26 18:58:33 +08:00
import 'package:scence_map/controllers/controller.dart';
2024-08-26 18:25:21 +08:00
import 'package:scence_map/controllers/plumController.dart';
2024-08-23 17:54:57 +08:00
import 'appbar.dart';
2024-08-31 17:57:19 +08:00
import 'pages/aim_point/aimpointController.dart';
2024-08-29 17:45:39 +08:00
import 'pages/history/history_record.dart';
2024-10-29 17:55:04 +08:00
import 'pages/login/login_page.dart';
import 'pages/login/my_routes.dart';
2024-09-03 18:05:49 +08:00
import 'pages/pass_track/view.dart';
2024-10-29 17:55:04 +08:00
import 'pages/setting/child_pages/XyChange/xy_change.dart';
import 'pages/setting/child_pages/persondetail/person_details.dart';
2024-09-05 12:06:03 +08:00
import 'pages/task/pile/pileNav/view.dart';
2024-09-03 18:05:49 +08:00
// import 'pages/pile/rightDra/pileGenerate.dart';
2024-08-29 17:45:39 +08:00
import 'pages/real/index.dart';
2024-08-30 17:57:33 +08:00
import 'pages/setting/child_pages/XyChange/connect.dart';
2024-08-29 17:45:39 +08:00
import 'pages/setting/setting_page.dart';
2024-08-30 17:57:33 +08:00
import 'service/user/loginprefs.dart';
2024-08-18 22:42:37 +08:00
2024-08-30 17:57:33 +08:00
final AppController appcontroller = Get.put(AppController());
Connect connect = Connect();
void main() async {
2024-08-18 22:42:37 +08:00
WidgetsFlutterBinding.ensureInitialized();
SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []); //设置全屏
2024-08-26 18:58:33 +08:00
Get.put(ScenceMapController());
2024-08-23 17:54:57 +08:00
Get.put(PlumDataController());
2024-08-31 17:57:19 +08:00
Get.put(AimPointerController());
2024-08-26 18:58:33 +08:00
Get.put(GnssController());
2024-08-30 17:57:33 +08:00
Get.put(AntennaController());
2024-09-03 18:05:49 +08:00
Get.put(AppController());
2024-10-29 17:55:04 +08:00
Get.put(LoginPageController());
Get.put(AccountLoginController());
Get.put(PhoneLoginController());
2024-08-30 17:57:33 +08:00
LoginPrefs loginPrefs = LoginPrefs();
String value =
await loginPrefs.init(); // await 关键字必须用在异步方法中 await等待异步方法执行完毕 异步方法必须用变量接收
if ('ok' == value) {
connect.init();
2024-10-29 17:55:04 +08:00
loginPrefs.removeToken(); //注释掉即能实现短时间二次登录不需要再重新登录
2024-08-30 17:57:33 +08:00
runApp(const MyApp());
}
2024-08-18 22:42:37 +08:00
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
2024-08-30 17:57:33 +08:00
return Obx(() {
return MaterialApp(
title: 'Flutter Demo',
theme: appcontroller.isDarkMode.value
? ThemeData.dark()
: ThemeData.light(),
2024-10-29 17:55:04 +08:00
debugShowCheckedModeBanner: false,
2024-08-30 17:57:33 +08:00
home: MyHomePage(title: 'Flutter Demo Home Page'),
2024-10-29 17:55:04 +08:00
initialRoute: "home",
onGenerateRoute: onGenerateRoute,
2024-08-30 17:57:33 +08:00
);
});
2024-08-18 22:42:37 +08:00
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
late bool isPortrait;
late double appBarHeight = 34.0;
2024-09-03 18:05:49 +08:00
2024-08-18 22:42:37 +08:00
final List<Widget> _pages = [
2024-08-29 17:45:39 +08:00
Real(),
2024-09-03 18:05:49 +08:00
PassTrack(
2024-10-29 17:55:04 +08:00
// date: '',
),
2024-09-03 18:05:49 +08:00
TaskManagePage(),
2024-08-29 17:45:39 +08:00
HistoryRecord(),
SettingPortrait()
2024-08-18 22:42:37 +08:00
];
@override
Widget build(BuildContext context) {
2024-08-23 17:54:57 +08:00
final size = MediaQuery.of(context).size;
2024-08-29 17:45:39 +08:00
2024-08-18 22:42:37 +08:00
return Scaffold(
2024-08-30 17:57:33 +08:00
resizeToAvoidBottomInset: false,
drawerEdgeDragWidth: 0.0, // 禁止通过滑动打开drawer
appBar: PreferredSize(
preferredSize: Size.fromHeight(appBarHeight),
child: CustomAppBar(
appBarHeight: 56,
2024-09-03 18:05:49 +08:00
currentIndex: appcontroller.currentIndex,
2024-08-18 22:42:37 +08:00
),
2024-08-30 17:57:33 +08:00
),
body: OrientationBuilder(
builder: (context, orientation) {
// final size = MediaQuery.of(context).size;
appBarHeight = Orientation.portrait == orientation ? 56.0 : 34.0;
isPortrait = Orientation.portrait == orientation ? true : false;
appBarHeight = Orientation.portrait == orientation ? 56.0 : 34.0;
if (!isPortrait) {
return Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
2024-09-03 18:05:49 +08:00
child: _pages[appcontroller.currentIndex.value],
2024-08-30 17:57:33 +08:00
),
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(() {
2024-09-03 18:05:49 +08:00
appcontroller.currentIndex.value = 0;
2024-08-30 17:57:33 +08:00
});
},
icon: const Icon(Icons.date_range_rounded),
2024-09-03 18:05:49 +08:00
color: appcontroller.currentIndex.value == 0
2024-08-30 17:57:33 +08:00
? const Color.fromARGB(255, 60, 95, 123)
: Colors.grey,
),
Align(
alignment: Alignment.center,
child: Text(
'实时',
style: TextStyle(
fontSize: 12,
2024-09-03 18:05:49 +08:00
color:
appcontroller.currentIndex.value ==
0
? const Color.fromARGB(
255, 60, 95, 123)
: Colors.grey,
2024-08-18 22:42:37 +08:00
),
),
2024-08-30 17:57:33 +08:00
),
],
),
const Divider(
height: 1, // 设置高度为1
thickness: 1,
),
//
Column(
children: [
IconButton(
onPressed: () {
setState(() {
2024-09-03 18:05:49 +08:00
appcontroller.currentIndex.value = 1;
2024-08-30 17:57:33 +08:00
});
},
icon: const Icon(Icons.map_outlined),
2024-09-03 18:05:49 +08:00
color: appcontroller.currentIndex.value == 1
2024-08-30 17:57:33 +08:00
? const Color.fromARGB(255, 60, 95, 123)
: Colors.grey,
),
Align(
alignment: Alignment.center,
child: Text(
'桩点',
style: TextStyle(
fontSize: 12,
2024-09-03 18:05:49 +08:00
color:
appcontroller.currentIndex.value ==
1
? const Color.fromARGB(
255, 60, 95, 123)
: Colors.grey,
2024-08-18 22:42:37 +08:00
),
),
2024-08-30 17:57:33 +08:00
),
],
),
const Divider(),
Column(
children: [
IconButton(
onPressed: () {
setState(() {
2024-09-03 18:05:49 +08:00
appcontroller.currentIndex.value = 2;
2024-08-30 17:57:33 +08:00
});
},
icon: const Icon(Icons.my_location_sharp),
2024-09-03 18:05:49 +08:00
color: appcontroller.currentIndex.value == 2
2024-08-30 17:57:33 +08:00
? const Color.fromARGB(255, 60, 95, 123)
: Colors.grey,
),
Align(
alignment: Alignment.center,
child: Text(
'任务',
style: TextStyle(
fontSize: 12,
2024-09-03 18:05:49 +08:00
color:
appcontroller.currentIndex.value ==
2
? const Color.fromARGB(
255, 60, 95, 123)
: Colors.grey,
2024-08-18 22:42:37 +08:00
),
),
2024-08-30 17:57:33 +08:00
),
],
),
const Divider(),
Column(
children: [
IconButton(
onPressed: () {
setState(() {
2024-09-03 18:05:49 +08:00
appcontroller.currentIndex.value = 3;
2024-08-30 17:57:33 +08:00
});
},
icon:
const Icon(Icons.table_chart_outlined),
2024-09-03 18:05:49 +08:00
color: appcontroller.currentIndex.value == 3
2024-08-30 17:57:33 +08:00
? const Color.fromARGB(255, 60, 95, 123)
: Colors.grey,
),
Align(
alignment: Alignment.center,
child: Text(
'历史',
style: TextStyle(
fontSize: 12,
2024-09-03 18:05:49 +08:00
color:
appcontroller.currentIndex.value ==
3
? const Color.fromARGB(
255, 60, 95, 123)
: Colors.grey,
2024-08-18 22:42:37 +08:00
),
),
2024-08-30 17:57:33 +08:00
),
],
),
const Divider(),
Column(
children: [
IconButton(
onPressed: () {
setState(() {
2024-09-03 18:05:49 +08:00
appcontroller.currentIndex.value = 4;
2024-08-30 17:57:33 +08:00
});
},
icon: const Icon(Icons.settings),
2024-09-03 18:05:49 +08:00
color: appcontroller.currentIndex.value == 4
2024-08-30 17:57:33 +08:00
? const Color.fromARGB(255, 60, 95, 123)
: Colors.grey,
),
Align(
alignment: Alignment.center,
child: Text(
'设置',
style: TextStyle(
fontSize: 12,
2024-09-03 18:05:49 +08:00
color:
appcontroller.currentIndex.value ==
4
? const Color.fromARGB(
255, 60, 95, 123)
: Colors.grey,
2024-08-18 22:42:37 +08:00
),
),
2024-08-30 17:57:33 +08:00
),
],
)
]);
//
}),
),
)
]);
} //
2024-08-18 22:42:37 +08:00
2024-08-30 17:57:33 +08:00
else {
// 竖屏布局,保持原有底部导航栏样式
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Expanded(
flex: 12,
2024-09-03 18:05:49 +08:00
child: _pages[appcontroller.currentIndex.value],
2024-08-30 17:57:33 +08:00
),
// VerticalDivider(),
Expanded(
flex: 1,
child: SizedBox(
height: 48,
child: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
2024-09-03 18:05:49 +08:00
currentIndex: appcontroller.currentIndex.value,
2024-08-30 17:57:33 +08:00
onTap: (index) {
setState(() {
2024-09-03 18:05:49 +08:00
appcontroller.currentIndex.value = index;
2024-08-30 17:57:33 +08:00
});
},
items: const [
BottomNavigationBarItem(
icon: Icon(Icons.date_range_rounded),
label: "实时"),
BottomNavigationBarItem(
icon: Icon(Icons.map_outlined), label: "计划"),
BottomNavigationBarItem(
icon: Icon(Icons.my_location_sharp),
2024-09-03 18:05:49 +08:00
label: "任务"),
2024-08-30 17:57:33 +08:00
BottomNavigationBarItem(
icon: Icon(Icons.table_chart_outlined),
label: "历史"),
BottomNavigationBarItem(
icon: Icon(Icons.settings), label: "设置"),
]),
2024-08-18 22:42:37 +08:00
),
2024-08-30 17:57:33 +08:00
)
]);
}
},
),
);
2024-08-18 22:42:37 +08:00
}
}