pile_nav_new/lib/appbar.dart
2024-11-15 17:42:52 +08:00

197 lines
7.3 KiB
Dart

import 'package:cpnav/pages/setting/setting_controller.dart';
import 'package:cpnav/pages/task/taskcontroller.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'main.dart';
import 'pages/aim_point/aimpoint_controller.dart';
import 'pages/real/real_controller.dart';
final AimPointerController aimcontroller = Get.find<AimPointerController>();
final RealController realcontroller = Get.find<RealController>();
final TaskController taskcontroller = Get.find<TaskController>();
final SettingController settingcontroller = Get.find<SettingController>();
class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
final double appBarHeight;
final RxInt _currentIndex;
final isCardVisible = false.obs;
final isDataVisible = false.obs;
CustomAppBar({
super.key,
required this.appBarHeight,
required RxInt currentIndex,
}) : _currentIndex = currentIndex;
@override
Widget build(BuildContext context) {
const textStyle = TextStyle(fontSize: 16);
return AppBar(
toolbarHeight: 40,
centerTitle: true, // 标题居中
title: Obx(() {
// pile_cm
// if (_currentIndex.value == 0) {
// return const Text("桩点:", style: textStyle);
// } else if (_currentIndex.value == 1) {
// return Text(
// "设备:${settingcontroller.currentDevice.value?.name ?? ""} | 任务:${taskcontroller.currentask.value.name}",
// style: textStyle);
// } else if (_currentIndex.value == 2) {
// return const Text("任务管理", style: textStyle);
// } else if (_currentIndex.value == 3) {
// return const Text("历史数据", style: textStyle);
// }else {
// return const Text("系统:", style: textStyle);
// }
if (_currentIndex.value == 0) {
return Text(
"设备:${settingcontroller.currentDevice.value?.name ?? ""} | 任务:${taskcontroller.currentask.value.name}",
style: textStyle);
} else if (_currentIndex.value == 1) {
return const Text("任务管理", style: textStyle);
} else if (_currentIndex.value == 2) {
return const Text("历史数据", style: textStyle);
} else {
return const Text("系统", style: textStyle);
}
}),
leading: null,
// title: _currentIndex.value == 0
// ? Obx(() => Text("桩点:${realController.pileId.value}",
// style: textStyle))
// : const Text("设备:", style: textStyle),
// // const Center(
// // child: Obx(() => Text("设备:", style: textStyle)),
// // ),
// title: Obx(() {
// if (_currentIndex.value == 1) {
// return const Text("设备:", style: textStyle);
// } else if (_currentIndex.value == 0) {
// return Text("桩点:${realController.pileId.value}",
// style: textStyle);
// } else {
// return const Text("系统:", style: textStyle);
// }
// }),
actions: [
Obx(
() => InkWell(
onTap: () {
appcontroller.isDarkMode.value = !appcontroller.isDarkMode.value;
},
child: Icon(
appcontroller.isDarkMode.value ? Icons.dark_mode : Icons.sunny,
size: 35,
),
),
),
const SizedBox(
width: 10,
),
Obx(
() => InkWell(
onTap: () {
// Navigator.push(context,
// MaterialPageRoute(builder: (context) => const ScenceMap())),
},
child: Image(
image: const AssetImage('images/satellite.png'),
// width: 40,
color: appcontroller.isDarkMode.value
? Colors.white70
: const Color.fromARGB(200, 29, 28, 28),
height: 40,
),
),
),
const SizedBox(
width: 10,
),
_currentIndex.value == 0
? Row(
children: [
Obx(
() => InkWell(
onTap: () {
// 点击图标时显示对点卡片
aimcontroller.isCardVisible.value =
!aimcontroller.isCardVisible.value; // 确保控制器已定义
aimcontroller.lastManualTapTime =
DateTime.now().millisecondsSinceEpoch;
},
child: Icon(
Icons.my_location_sharp,
size: 35,
color: aimcontroller.isCardVisible.value
? Colors.blue
// : const Color.fromARGB(200, 29, 28, 28),
: (appcontroller.isDarkMode.value
? Colors.white70
: const Color.fromARGB(200, 29, 28, 28)),
), // 新增图标
),
),
const SizedBox(
width: 10,
),
Obx(
() => InkWell(
onTap: () {
realcontroller.isDataVisible.value =
!realcontroller.isDataVisible.value; // 更新控制器中的值
},
child: Icon(
Icons.date_range_rounded,
size: 35,
color: isDataVisible.value
? Colors.blue
: (appcontroller.isDarkMode.value
? Colors.white70
: const Color.fromARGB(200, 29, 28, 28)),
), // 新增图标
),
),
const SizedBox(
width: 10,
),
// UnconstrainedBox(
// child: SizedBox(
// height: 30,
// child: Builder(
// builder: (context) => InkWell(
// child: Icon(
// Icons.settings_outlined,
// size: 35,
// color: appcontroller.isDarkMode.value
// ? Colors.white70
// : const Color.fromARGB(200, 29, 28, 28),
// ),
// onTap: () => Scaffold.of(context).openEndDrawer(),
// ),
// ),
// ),
// )
],
)
: const Text(""),
// Obx(() => Icon(
// blueToothController.connectedType.value == ConnectType.wifi
// ? Icons.wifi
// : (blueToothController.connectedType.value ==
// ConnectType.bluetooth
// ? Icons.bluetooth
// : Icons.close),
// color: Colors.green,
// size: 30,
// ))
],
);
}
@override
Size get preferredSize => Size.fromHeight(appBarHeight);
}