pile_nav_new/lib/appbar.dart

177 lines
6.2 KiB
Dart
Raw Normal View History

2024-08-18 22:42:37 +08:00
import 'package:flutter/material.dart';
import 'package:get/get.dart';
2024-08-29 17:45:39 +08:00
import 'main.dart';
2024-11-06 17:23:29 +08:00
import 'pages/aim_point/aimpoint_controller.dart';
import 'pages/real/real_controller.dart';
2024-08-18 22:42:37 +08:00
2024-08-31 17:57:19 +08:00
final AimPointerController aimcontroller = Get.find();
2024-08-30 17:57:33 +08:00
final RealController realcontroller = Get.find();
2024-08-18 22:42:37 +08:00
class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
final double appBarHeight;
final RxInt _currentIndex;
2024-08-30 17:57:33 +08:00
2024-08-18 22:42:37 +08:00
final isCardVisible = false.obs;
final isDataVisible = false.obs;
2024-08-30 17:57:33 +08:00
CustomAppBar({
2024-11-06 17:23:29 +08:00
super.key,
2024-08-30 17:57:33 +08:00
required this.appBarHeight,
required RxInt currentIndex,
}) : _currentIndex = currentIndex;
2024-08-18 22:42:37 +08:00
@override
Widget build(BuildContext context) {
const textStyle = TextStyle(fontSize: 16);
return AppBar(
toolbarHeight: 40,
centerTitle: true, // 标题居中
title: Obx(() {
if (_currentIndex.value == 0) {
return const Text("桩点:", style: textStyle);
} else if (_currentIndex.value == 1) {
return const Text("设备:", style: textStyle);
2024-09-03 18:05:49 +08:00
} else if (_currentIndex.value == 2) {
return const Text("任务管理", style: textStyle);
2024-08-18 22:42:37 +08:00
} else {
return const Text("系统:", style: textStyle);
}
}),
2024-11-06 17:23:29 +08:00
leading: null,
2024-08-18 22:42:37 +08:00
// 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: [
2024-08-30 17:57:33 +08:00
Obx(
() => InkWell(
onTap: () {
appcontroller.isDarkMode.value = !appcontroller.isDarkMode.value;
},
child: Icon(
appcontroller.isDarkMode.value ? Icons.dark_mode : Icons.sunny,
size: 35,
),
2024-08-18 22:42:37 +08:00
),
),
const SizedBox(
width: 10,
),
2024-08-30 17:57:33 +08:00
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,
),
2024-08-18 22:42:37 +08:00
),
),
const SizedBox(
width: 10,
),
_currentIndex.value == 1
? Row(
children: [
Obx(
() => InkWell(
onTap: () {
// 点击图标时显示对点卡片
2024-08-31 17:57:19 +08:00
aimcontroller.isCardVisible.value =
!aimcontroller.isCardVisible.value; // 确保控制器已定义
2024-08-30 17:57:33 +08:00
2024-08-31 17:57:19 +08:00
aimcontroller.lastManualTapTime =
DateTime.now().millisecondsSinceEpoch;
2024-08-18 22:42:37 +08:00
},
child: Icon(
Icons.my_location_sharp,
size: 35,
2024-08-31 17:57:19 +08:00
color: aimcontroller.isCardVisible.value
2024-08-18 22:42:37 +08:00
? Colors.blue
// : const Color.fromARGB(200, 29, 28, 28),
2024-08-30 17:57:33 +08:00
: (appcontroller.isDarkMode.value
2024-08-18 22:42:37 +08:00
? Colors.white70
: const Color.fromARGB(200, 29, 28, 28)),
), // 新增图标
),
),
const SizedBox(
width: 10,
),
Obx(
() => InkWell(
onTap: () {
2024-08-30 17:57:33 +08:00
realcontroller.isDataVisible.value =
!realcontroller.isDataVisible.value; // 更新控制器中的值
2024-08-18 22:42:37 +08:00
},
child: Icon(
Icons.date_range_rounded,
size: 35,
color: isDataVisible.value
? Colors.blue
2024-08-30 17:57:33 +08:00
: (appcontroller.isDarkMode.value
2024-08-18 22:42:37 +08:00
? Colors.white70
: const Color.fromARGB(200, 29, 28, 28)),
), // 新增图标
),
),
const SizedBox(
width: 10,
),
2024-09-03 18:05:49 +08:00
// 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(),
// ),
// ),
// ),
// )
2024-08-18 22:42:37 +08:00
],
)
: 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);
}