diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..4c9f059 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,85 @@ +{ + // 使用 IntelliSense 了解相关属性。 + // 悬停以查看现有属性的描述。 + // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "cpnav", + "request": "launch", + "type": "dart" + }, + { + "name": "cpnav (profile mode)", + "request": "launch", + "type": "dart", + "flutterMode": "profile" + }, + { + "name": "cpnav (release mode)", + "request": "launch", + "type": "dart", + "flutterMode": "release" + }, + { + "name": "pass_track", + "cwd": "plugins\\pass_track", + "request": "launch", + "type": "dart" + }, + { + "name": "pass_track (profile mode)", + "cwd": "plugins\\pass_track", + "request": "launch", + "type": "dart", + "flutterMode": "profile" + }, + { + "name": "pass_track (release mode)", + "cwd": "plugins\\pass_track", + "request": "launch", + "type": "dart", + "flutterMode": "release" + }, + { + "name": "scence_map", + "cwd": "plugins\\scence_map", + "request": "launch", + "type": "dart" + }, + { + "name": "scence_map (profile mode)", + "cwd": "plugins\\scence_map", + "request": "launch", + "type": "dart", + "flutterMode": "profile" + }, + { + "name": "scence_map (release mode)", + "cwd": "plugins\\scence_map", + "request": "launch", + "type": "dart", + "flutterMode": "release" + }, + { + "name": "example", + "cwd": "plugins\\pass_track\\example", + "request": "launch", + "type": "dart" + }, + { + "name": "example (profile mode)", + "cwd": "plugins\\pass_track\\example", + "request": "launch", + "type": "dart", + "flutterMode": "profile" + }, + { + "name": "example (release mode)", + "cwd": "plugins\\pass_track\\example", + "request": "launch", + "type": "dart", + "flutterMode": "release" + } + ] +} \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index 395fb4a..0868379 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -68,7 +68,7 @@ class _MyHomePageState extends State { final _currentIndex = 0.obs; final List _pages = [ - PassTrackWidget( + PassTrackView( date: '', ), Container( diff --git a/lib/pages/pass_track/controller.dart b/lib/pages/pass_track/controller.dart index 23d2c30..080406b 100644 --- a/lib/pages/pass_track/controller.dart +++ b/lib/pages/pass_track/controller.dart @@ -1,13 +1,11 @@ import 'dart:ui'; - import 'package:get/get.dart'; import 'package:scence_map/controller.dart'; import 'package:cpnav/service/base.dart'; import 'package:pass_track/pass_track.dart'; import 'sevice/file_handle.dart'; - FileHandle fileHandle = FileHandle(); class PassTrackController extends GetxController { @@ -16,6 +14,7 @@ class PassTrackController extends GetxController { String projCode; String projType; + var speed = 1.obs; late final GetServices service; // final PassTrack _passTrackPlugin; PassTrackController(this.projCode, this.projType); diff --git a/lib/pages/pass_track/iconContainer.dart b/lib/pages/pass_track/iconContainer.dart index 689eea9..92d9316 100644 --- a/lib/pages/pass_track/iconContainer.dart +++ b/lib/pages/pass_track/iconContainer.dart @@ -62,7 +62,7 @@ class _IconContainerState extends State { decoration: BoxDecoration( color: Colors.transparent, border: Border.all( - color: Color.fromARGB(255, 54, 52, 52), + color: const Color.fromARGB(255, 54, 52, 52), width: 1.0, ), borderRadius: BorderRadius.circular(5.0), @@ -134,7 +134,7 @@ class _IconContainerState extends State { decoration: BoxDecoration( color: Colors.transparent, border: Border.all( - color: Color.fromARGB(255, 54, 52, 52), + color: const Color.fromARGB(255, 54, 52, 52), width: 1.0, ), borderRadius: BorderRadius.circular(5.0), @@ -206,7 +206,7 @@ class _IconContainerState extends State { return Container( width: 33, height: 33, - margin: EdgeInsets.symmetric(vertical: 2.0), + margin: const EdgeInsets.symmetric(vertical: 2.0), decoration: BoxDecoration( color: _iconColors[icon], border: Border.all( @@ -229,7 +229,7 @@ class _IconContainerState extends State { return Container( width: 33, height: 33, - margin: EdgeInsets.symmetric(vertical: 2.0), + margin: const EdgeInsets.symmetric(vertical: 2.0), decoration: BoxDecoration( color: _iconColors[icon], border: Border.all( diff --git a/lib/pages/pass_track/view.dart b/lib/pages/pass_track/view.dart index 6438b19..2529516 100644 --- a/lib/pages/pass_track/view.dart +++ b/lib/pages/pass_track/view.dart @@ -15,6 +15,7 @@ import "package:pass_track/pass_track.dart"; import "package:pass_track/pass_track_platform_interface.dart"; import "controller.dart"; import "dart:ffi" as ffi; + // import '../login_in/connect/bluetooth_page.dart'; // import '../login_in/connect/config.dart'; // import '../login_in/connect/connect_type.dart'; @@ -26,131 +27,126 @@ import "dart:ffi" as ffi; ScenceMapController mapcontroller = Get.put(ScenceMapController()); -class PassTrackWidget extends StatefulWidget { - final String date; - final controller; - - const PassTrackWidget({super.key, required this.date, this.controller}); - - @override - State createState() => _PasstrackState(); -} - -class _PasstrackState extends State { +class PassTrackView extends GetView { final GlobalKey> _popupMenuKey = GlobalKey>(); - final controller = Get.put(PassTrackController("WXLMB", "cp_road")); - String str = "播放"; - int sWidth = 800; - int sHeight = 800; - int bits = -1; - int speed = 50; - List speedList = [1, 2, 10, 20, 50, 100, 200, 500]; + // final controller = Get.put(PassTrackController("WXLMB", "cp_road")); + final String str = "播放"; + // int sWidth = 800; + // int sHeight = 800; + // int bits = -1; + // int speed = 50; + // int maxLength = 200; - late SfRangeValues _rangevalues; + // late SfRangeValues _rangevalues; final PassTrack _passTrackPlugin = PassTrack(); - @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(); + PassTrackView({Key? key}) : super(key: key); - // // 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); - // } + // @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(); - // 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(); + // // 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); + // } - 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(); - // 获取当前时间 - }); - }); - } + // 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(); - Future initPlatformState() async { - String platformVersion; - try { - platformVersion = await _passTrackPlugin.getPlatformVersion() ?? - 'Unknown platform version'; - } on Exception { - platformVersion = 'Failed to get platform version.'; - } - await _passTrackPlugin.create(sWidth, sWidth); - fileHandle.textureId = await _passTrackPlugin.getTextureId() ?? -1; - print("textureId: ${fileHandle.textureId}"); + // 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(); + // // 获取当前时间 + // }); + // }); + // } - if (!mounted) Exception('Failed to get textureId.'); + // Future 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}"); - setState(() { - platformVersion = platformVersion; - }); - return; - } + // if (!mounted) Exception('Failed to get textureId.'); + + // setState(() { + // platformVersion = platformVersion; + // }); + // return; + // } @override Widget build(BuildContext context) { final size = MediaQuery.of(context).size; var isPortrait = MediaQuery.of(context).orientation == Orientation.portrait; + var controller = this.controller; return OrientationBuilder(builder: (context, orientation) { return Stack( children: [ ScenceMapView( children: [ Positioned( - top: 0, - left: 0, + top: mapcontroller.top, + left: mapcontroller.left, child: SizedBox( - width: sWidth * 1.0, - height: sWidth * 1.0, + width: mapcontroller.width, + height: mapcontroller.height, // child: Text('Running on: $_platformVersion\n'), child: Texture(textureId: fileHandle.textureId))), ], @@ -177,10 +173,10 @@ class _PasstrackState extends State { minorTicksPerInterval: 1, stepSize: 1, onChanged: (SfRangeValues values) { - setState(() { - _rangevalues = SfRangeValues(values.start.roundToDouble(), - values.end.roundToDouble()); - }); + // setState(() { + // _rangevalues = SfRangeValues(values.start.roundToDouble(), + // values.end.roundToDouble()); + // }); }, ), ), @@ -195,20 +191,20 @@ class _PasstrackState extends State { width: 74, child: ElevatedButton( style: ButtonStyle( - backgroundColor: MaterialStateProperty.all( + backgroundColor: WidgetStateProperty.all( str == "播放" ? Colors.blue : Colors.red, ), ), onPressed: () { if (str == "播放") { - _passTrackPlugin.playTrack(0, 10000, true, 50, ffi.nullptr); + _passTrackPlugin.playTrack( + 0, 10000, true, 50, ffi.nullptr); } else { _passTrackPlugin.playPause(); } - setState(() { - str = str == "播放" ? "暂停" : "播放"; - }); - + // setState(() { + // str = str == "播放" ? "暂停" : "播放"; + // }); }, child: Text( str, @@ -234,12 +230,14 @@ class _PasstrackState extends State { child: Row( mainAxisSize: MainAxisSize.min, children: [ - Text( - "$speed X", - style: const TextStyle( - fontSize: 11, color: Colors.black), + Obx( + () => Text( + "${controller.speed.value} X", + style: const TextStyle( + fontSize: 11, color: Colors.black), + ), ), - Container( + SizedBox( width: 25, child: PopupMenuButton( key: _popupMenuKey, @@ -247,9 +245,7 @@ class _PasstrackState extends State { icon: const Icon(Icons.arrow_drop_up, color: Color.fromARGB(255, 47, 48, 47)), onSelected: (int value) { - setState(() { - speed = value; - }); + controller.speed.value = value; }, // style: ButtonStyle( // minimumSize: MaterialStateProperty.all( @@ -262,7 +258,8 @@ class _PasstrackState extends State { return PopupMenuItem( height: 30, value: speed, - child: Text("$speed X速度"), + child: Obx(() => + Text("${controller.speed.value} X速度")), ); }).toList(); }, diff --git a/plugins/pass_track b/plugins/pass_track index 1318d54..65de63a 160000 --- a/plugins/pass_track +++ b/plugins/pass_track @@ -1 +1 @@ -Subproject commit 1318d54e5901967be53f6ceba0825df45df9d167 +Subproject commit 65de63acc0c565de548b02b15be6554b24ebad11 diff --git a/plugins/scence_map b/plugins/scence_map index 2eaf69b..ac21792 160000 --- a/plugins/scence_map +++ b/plugins/scence_map @@ -1 +1 @@ -Subproject commit 2eaf69b52fb3965a920202f878a8416a164d6e15 +Subproject commit ac2179219ba52d0c91dfd51470fd1d7ebaae69be