diff --git a/lib/main.dart b/lib/main.dart index 0868379..f51dd17 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,4 +1,5 @@ import 'package:cpnav/appbar.dart'; +import 'package:cpnav/pages/pass_track/controller.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:get/get.dart'; @@ -8,7 +9,7 @@ import 'pages/pass_track/view.dart'; void main() { WidgetsFlutterBinding.ensureInitialized(); SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []); //设置全屏 - + Get.put(PassTrackController('WXLMB', 'cp_road')); runApp(const MyApp()); } @@ -69,8 +70,8 @@ class _MyHomePageState extends State { final _currentIndex = 0.obs; final List _pages = [ PassTrackView( - date: '', - ), + // date: '', + ), Container( color: Colors.green, ), diff --git a/lib/pages/pass_track/controller.dart b/lib/pages/pass_track/controller.dart index 080406b..43dae7f 100644 --- a/lib/pages/pass_track/controller.dart +++ b/lib/pages/pass_track/controller.dart @@ -1,5 +1,5 @@ import 'dart:ui'; - +import "dart:ffi" as ffi; import 'package:get/get.dart'; import 'package:scence_map/controller.dart'; import 'package:cpnav/service/base.dart'; @@ -7,19 +7,24 @@ import 'package:pass_track/pass_track.dart'; import 'sevice/file_handle.dart'; FileHandle fileHandle = FileHandle(); +ScenceMapController mapcontroller = Get.put(ScenceMapController()); class PassTrackController extends GetxController { - int allLen = 0; + var tileCount = 0.obs; + var tileFirst = 0.obs; + var tileLast = 0.obs; final mapController = Get.put(ScenceMapController()); String projCode; String projType; var speed = 1.obs; late final GetServices service; - // final PassTrack _passTrackPlugin; + PassTrackController(this.projCode, this.projType); Map deviceMap = {}; Map coorTransMap = {}; + // final PassTrack _passTrackPlugin; + final PassTrack _passTrackPlugin = PassTrack(); @override void onInit() { super.onInit(); @@ -28,6 +33,72 @@ class PassTrackController extends GetxController { // loadSideLine(); loadBindDevice(); // getHisFileList(); + var future = getHisFileList(_passTrackPlugin); + + // 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(); + + // // 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); + // } + + // 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(); + + f.then((void _) { + _passTrackPlugin.setGridColor(const Color.fromARGB(255, 0, 0, 0).value); + _passTrackPlugin.drawGrid(); + + future.then((value) { + _passTrackPlugin.setScale(1); + for (var TID in deviceMap.keys) { + _passTrackPlugin.addDevice(int.parse(TID), 0); + } + for (var item in 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()}"); + tileCount.value = _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(); + // 获取当前时间 + }); + }); } loadBindDevice() async { @@ -89,12 +160,34 @@ class PassTrackController extends GetxController { var jsData = await GetServices().getHisFil1(file); print("have message"); int len = fileHandle.resolveJson(jsData, passTrackPlugin); - allLen += len; - if (allLen >= 20000) { + tileCount.value += len; + if (tileCount.value >= 20000) { break; } } coorTransMap = fileHandle.pointsMap; - return allLen; + return tileCount.value; + } + + Future initPlatformState() async { + String platformVersion; + try { + platformVersion = await _passTrackPlugin.getPlatformVersion() ?? + 'Unknown platform version'; + } on Exception { + platformVersion = 'Failed to get platform version.'; + } + await _passTrackPlugin.create(600, 600); + // mapcontroller.height.toInt(), mapcontroller.width.toInt()); + fileHandle.textureId = await _passTrackPlugin.getTextureId() ?? -1; + print("textureId: ${fileHandle.textureId}"); + print("${mapcontroller.height.toInt()}"); + + // if (!mounted) Exception('Failed to get textureId.'); + + // setState(() { + // platformVersion = platformVersion; + // }); + return; } } diff --git a/lib/pages/pass_track/view.dart b/lib/pages/pass_track/view.dart index 2529516..8b9bb39 100644 --- a/lib/pages/pass_track/view.dart +++ b/lib/pages/pass_track/view.dart @@ -141,7 +141,13 @@ class PassTrackView extends GetView { children: [ ScenceMapView( children: [ - Positioned( + + ], + onUpdate: (Offset center, double scale, double rotation) { + print("center:$center scale:$scale rotation:$rotation"); + }, + ), + Positioned( top: mapcontroller.top, left: mapcontroller.left, child: SizedBox( @@ -149,35 +155,31 @@ class PassTrackView extends GetView { height: mapcontroller.height, // child: Text('Running on: $_platformVersion\n'), child: Texture(textureId: fileHandle.textureId))), - ], - onUpdate: (Offset center, double scale, double rotation) { - print("center:$center scale:$scale rotation:$rotation"); - }, - ), Positioned( width: isPortrait ? size.width * .63 : size.width * .41, left: isPortrait ? 190 : 200, bottom: 30, child: Container( padding: const EdgeInsets.only(bottom: 5), - child: SfRangeSlider( - min: 0.0, - // max: maxLength, - max: controller.allLen > 0 - ? controller.allLen - : 1.0, // 确保 max 大于 0 - values: _rangevalues, - showTicks: false, - showLabels: false, - enableTooltip: true, - minorTicksPerInterval: 1, - stepSize: 1, - onChanged: (SfRangeValues values) { - // setState(() { - // _rangevalues = SfRangeValues(values.start.roundToDouble(), - // values.end.roundToDouble()); - // }); - }, + 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(); + }, + ), ), ), ), diff --git a/plugins/pass_track b/plugins/pass_track index 65de63a..ad96316 160000 --- a/plugins/pass_track +++ b/plugins/pass_track @@ -1 +1 @@ -Subproject commit 65de63acc0c565de548b02b15be6554b24ebad11 +Subproject commit ad96316e993e3bbb2ca2b5b360b2fb5b6a50f0d2