cpnav/lib/pages/pass_track/view.dart

313 lines
12 KiB
Dart
Raw Normal View History

2024-08-18 22:42:37 +08:00
//字体
2024-08-19 18:31:59 +08:00
import 'package:bottom_picker/resources/arrays.dart';
2024-08-18 22:42:37 +08:00
import 'package:flutter/material.dart';
2024-08-19 18:31:59 +08:00
import 'package:flutter/rendering.dart';
import 'package:flutter/scheduler.dart';
2024-08-18 22:42:37 +08:00
import 'package:flutter/widgets.dart';
import 'package:get/get.dart';
2024-08-19 18:31:59 +08:00
import 'package:scence_map/controller.dart';
2024-08-18 22:42:37 +08:00
import 'package:scence_map/scence_map.dart';
2024-08-21 17:38:18 +08:00
2024-08-19 18:31:59 +08:00
import 'package:syncfusion_flutter_sliders/sliders.dart';
2024-08-20 17:44:39 +08:00
import 'iconContainer.dart';
2024-08-18 22:42:37 +08:00
import "controller.dart";
2024-09-06 09:52:06 +08:00
import "package:pass_track/pass_track.dart";
import "package:pass_track/pass_track_platform_interface.dart";
import "controller.dart";
import "dart:ffi" as ffi;
2024-09-10 08:41:48 +08:00
2024-08-18 22:42:37 +08:00
// import '../login_in/connect/bluetooth_page.dart';
// import '../login_in/connect/config.dart';
// import '../login_in/connect/connect_type.dart';
// import '../login_in/getx/blue_tooth.dart';
// import '../setting/antenna_setting.dart';
// import '../setting/person_details.dart';
// import '../setting/wifi_page.dart';
// import '../setting/xy_change.dart';
2024-08-19 18:31:59 +08:00
ScenceMapController mapcontroller = Get.put(ScenceMapController());
2024-09-10 08:41:48 +08:00
class PassTrackView extends GetView<PassTrackController> {
2024-08-21 17:38:18 +08:00
final GlobalKey<PopupMenuButtonState<int>> _popupMenuKey =
GlobalKey<PopupMenuButtonState<int>>();
2024-09-10 08:41:48 +08:00
// final controller = Get.put(PassTrackController("WXLMB", "cp_road"));
final String str = "播放";
// int sWidth = 800;
// int sHeight = 800;
// int bits = -1;
// int speed = 50;
2024-09-06 09:11:06 +08:00
// int maxLength = 200;
2024-09-10 08:41:48 +08:00
// late SfRangeValues _rangevalues;
2024-09-06 15:16:09 +08:00
final PassTrack _passTrackPlugin = PassTrack();
2024-09-06 11:15:53 +08:00
2024-09-10 08:41:48 +08:00
PassTrackView({Key? key}) : super(key: key);
2024-08-18 22:42:37 +08:00
2024-09-10 08:41:48 +08:00
// @override
// initState() {
// super.initState();
// var maxLen =
// controller.allLen > 0 ? controller.allLen : 1.0; // 确保 maxLen 大于 0
// _rangevalues = SfRangeValues(0.0, maxLen);
// SchedulerBinding.instance.addPostFrameCallback((_) async {
// sWidth = sqrt(screen.width * screen.width + screen.height * screen.height)
// .ceil();
2024-08-19 18:31:59 +08:00
2024-09-10 08:41:48 +08:00
// // scenceMapController.scale = passTrackPlugin.passTrack_getScale() * 1.0;
// fileHandle.date = widget.date;
// await fileHandle.init();
// //在帧绘制完成后执行数据渲染
// // await initPlatformState();
// if (fileHandle.pointData.isNotEmpty) {
// DecodeDataObj obj = fileHandle.pointData[0].obj!;
// scenceMapController.centerXY = Offset(obj.y / 20, obj.x / 20);
// }
2024-09-09 15:08:41 +08:00
2024-09-10 08:41:48 +08:00
// for (var item in fileHandle.deviceList) {
// if (item["point"] != null) {
// bits = item["bits"];
// break;
// }
// }
// // passTrackPlugin.map_setCenterDevice(bits);
// setState(() {
// if (fileHandle.pointData.isNotEmpty) {
// maxLength = fileHandle.pointData.length;
// // _value = maxLength;
// _rangevalues = SfRangeValues(0.0, maxLength.toDouble());
// }
// });
// });
// var f = initPlatformState();
// var future = controller.getHisFileList(_passTrackPlugin);
// f.then((void _) {
// _passTrackPlugin.setGridColor(const Color.fromARGB(255, 0, 0, 0).value);
// _passTrackPlugin.drawGrid();
2024-08-19 18:31:59 +08:00
2024-09-10 08:41:48 +08:00
// future.then((value) {
// _passTrackPlugin.setScale(1);
// for (var TID in controller.deviceMap.keys) {
// _passTrackPlugin.addDevice(int.parse(TID), 0);
// }
// for (var item in controller.coorTransMap.entries) {
// print("tid:${item.key} value:${item.value}");
// }
// // 统计用时 获取当前时间
// var start = DateTime.now().millisecondsSinceEpoch;
// // _passTrackPlugin.generateTile(0, value);
// _passTrackPlugin.waitForTile(() {
// var start = DateTime.now().millisecondsSinceEpoch;
// print("len: ${_passTrackPlugin.allTileCnt()}");
// _rangevalues = SfRangeValues(0, _passTrackPlugin.allTileCnt());
// _passTrackPlugin.playTrack(
// 0, _passTrackPlugin.allTileCnt(), true, 0, ffi.nullptr);
// var end = DateTime.now().millisecondsSinceEpoch;
// print("play: ${end - start}");
// });
// // _passTrackPlugin.drawGrid();
// // 获取当前时间
// });
// });
// }
2024-08-19 18:31:59 +08:00
2024-09-10 08:41:48 +08:00
// Future<void> initPlatformState() async {
// String platformVersion;
// try {
// platformVersion = await _passTrackPlugin.getPlatformVersion() ??
// 'Unknown platform version';
// } on Exception {
// platformVersion = 'Failed to get platform version.';
// }
// await _passTrackPlugin.create(
// mapcontroller.height.toInt(), mapcontroller.width.toInt());
// fileHandle.textureId = await _passTrackPlugin.getTextureId() ?? -1;
// print("textureId: ${fileHandle.textureId}");
2024-08-19 18:31:59 +08:00
2024-09-10 08:41:48 +08:00
// if (!mounted) Exception('Failed to get textureId.');
// setState(() {
// platformVersion = platformVersion;
// });
// return;
// }
2024-08-18 22:42:37 +08:00
@override
Widget build(BuildContext context) {
2024-08-19 18:31:59 +08:00
final size = MediaQuery.of(context).size;
var isPortrait = MediaQuery.of(context).orientation == Orientation.portrait;
2024-09-10 08:41:48 +08:00
var controller = this.controller;
2024-08-20 17:44:39 +08:00
return OrientationBuilder(builder: (context, orientation) {
return Stack(
children: [
ScenceMapView(
2024-09-06 15:16:09 +08:00
children: [
2024-09-10 14:31:09 +08:00
Positioned(
2024-09-10 08:41:48 +08:00
top: mapcontroller.top,
left: mapcontroller.left,
2024-09-07 17:54:29 +08:00
child: SizedBox(
2024-09-10 08:41:48 +08:00
width: mapcontroller.width,
height: mapcontroller.height,
2024-09-07 17:54:29 +08:00
// child: Text('Running on: $_platformVersion\n'),
child: Texture(textureId: fileHandle.textureId))),
2024-09-10 14:31:09 +08:00
],
onUpdate: (Offset center, double scale, double rotation) {
print("center:$center scale:$scale rotation:$rotation");
},
),
2024-08-20 17:44:39 +08:00
Positioned(
2024-08-21 17:38:18 +08:00
width: isPortrait ? size.width * .63 : size.width * .41,
2024-08-20 17:44:39 +08:00
left: isPortrait ? 190 : 200,
bottom: 30,
child: Container(
padding: const EdgeInsets.only(bottom: 5),
2024-09-10 14:15:52 +08:00
child: Obx(
() => SfRangeSlider(
min: 0.0,
// max: maxLength,
max: controller.tileCount.value > 0
? controller.tileCount.value
: 1.0, // 确保 max 大于 0
values: SfRangeValues(
controller.tileFirst.value, controller.tileLast.value),
showTicks: false,
showLabels: false,
enableTooltip: true,
minorTicksPerInterval: 1,
stepSize: 1,
onChanged: (SfRangeValues values) {
controller.tileFirst.value = values.start.toInt();
controller.tileLast.value = values.end.toInt();
},
),
2024-08-19 18:31:59 +08:00
),
2024-08-20 17:44:39 +08:00
),
),
Positioned(
left: isPortrait ? 190 : 200,
bottom: 0,
child: Row(
children: [
const SizedBox(width: 18),
SizedBox(
width: 74,
child: ElevatedButton(
2024-08-19 18:31:59 +08:00
style: ButtonStyle(
2024-09-10 08:41:48 +08:00
backgroundColor: WidgetStateProperty.all<Color?>(
2024-08-19 18:31:59 +08:00
str == "播放" ? Colors.blue : Colors.red,
),
),
onPressed: () {
2024-09-09 15:08:41 +08:00
if (str == "播放") {
2024-09-10 08:41:48 +08:00
_passTrackPlugin.playTrack(
0, 10000, true, 50, ffi.nullptr);
2024-09-09 15:08:41 +08:00
} else {
_passTrackPlugin.playPause();
}
2024-09-10 08:41:48 +08:00
// setState(() {
// str = str == "播放" ? "暂停" : "播放";
// });
2024-08-19 18:31:59 +08:00
},
child: Text(
str,
2024-08-20 17:44:39 +08:00
style: const TextStyle(fontSize: 12, color: Colors.black),
),
2024-08-19 18:31:59 +08:00
),
),
2024-08-20 17:44:39 +08:00
const SizedBox(width: 5),
2024-08-21 17:38:18 +08:00
GestureDetector(
onTap: () {
// 触发 PopupMenuButton 的点击事件
final dynamic state = _popupMenuKey.currentState;
state.showButtonMenu();
},
child: Container(
width: 70,
height: 35,
padding: const EdgeInsets.symmetric(horizontal: 6.0),
decoration: BoxDecoration(
color: const Color.fromARGB(255, 255, 255, 255),
border: Border.all(color: Colors.black),
2024-08-20 17:44:39 +08:00
),
2024-08-21 17:38:18 +08:00
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
2024-09-10 08:41:48 +08:00
Obx(
() => Text(
"${controller.speed.value} X",
style: const TextStyle(
fontSize: 11, color: Colors.black),
),
2024-08-21 17:38:18 +08:00
),
2024-09-10 08:41:48 +08:00
SizedBox(
2024-08-21 17:38:18 +08:00
width: 25,
child: PopupMenuButton<int>(
key: _popupMenuKey,
padding: const EdgeInsets.all(1.0),
icon: const Icon(Icons.arrow_drop_up,
color: Color.fromARGB(255, 47, 48, 47)),
onSelected: (int value) {
2024-09-10 08:41:48 +08:00
controller.speed.value = value;
2024-08-21 17:38:18 +08:00
},
// style: ButtonStyle(
// minimumSize: MaterialStateProperty.all<Size>(
// Size(48, 48)), // 设置最小点击区域
// tapTargetSize: MaterialTapTargetSize
// .shrinkWrap, // 设置点击区域大小
// ),
itemBuilder: (BuildContext context) {
return speedList.map((int speed) {
return PopupMenuItem<int>(
height: 30,
value: speed,
2024-09-10 08:41:48 +08:00
child: Obx(() =>
Text("${controller.speed.value} X速度")),
2024-08-21 17:38:18 +08:00
);
}).toList();
},
),
),
],
)),
2024-08-19 18:31:59 +08:00
),
2024-08-20 17:44:39 +08:00
const SizedBox(width: 12),
Column(
children: [
const Text("此处遍数0"),
StreamBuilder<DateTime>(
stream: Stream.periodic(
const Duration(seconds: 1), (_) => DateTime.now()),
builder: (context, snapshot) {
if (snapshot.hasData) {
final dateTime = snapshot.data!.toLocal();
final formattedDate =
"${dateTime.year % 100}-${dateTime.month.toString().padLeft(2, '0')}-${dateTime.day.toString().padLeft(2, '0')}";
final formattedTime =
"${dateTime.hour.toString().padLeft(2, '0')}:${dateTime.minute.toString().padLeft(2, '0')}:${dateTime.second.toString().padLeft(2, '0')}";
return Text(
"$formattedDate $formattedTime",
style: const TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold,
),
);
} else {
return const Text(
"加载中...",
style: TextStyle(
fontSize: 16, fontWeight: FontWeight.bold),
);
}
},
),
],
2024-09-06 15:16:09 +08:00
),
2024-08-20 17:44:39 +08:00
],
2024-08-19 18:31:59 +08:00
),
),
2024-08-20 17:44:39 +08:00
IconContainer()
],
);
});
2024-08-18 22:42:37 +08:00
}
}