From 7d9626fafbe00d0170e8dac04f3b1e5a66350c99 Mon Sep 17 00:00:00 2001 From: tanlinxing Date: Wed, 21 Aug 2024 17:38:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=95=E9=83=A8=E9=83=A8=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .flutter-plugins-dependencies | 2 +- lib/pages/pass_track/iconContainer.dart | 182 ++++++++++++++++++------ lib/pages/pass_track/view.dart | 96 +++++++------ 3 files changed, 196 insertions(+), 84 deletions(-) diff --git a/.flutter-plugins-dependencies b/.flutter-plugins-dependencies index 7bd5548..8910ae0 100644 --- a/.flutter-plugins-dependencies +++ b/.flutter-plugins-dependencies @@ -1 +1 @@ -{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"path_provider_foundation","path":"C:\\\\Users\\\\Administrator\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.4.0\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"android":[{"name":"path_provider_android","path":"C:\\\\Users\\\\Administrator\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_android-2.2.10\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"path_provider_foundation","path":"C:\\\\Users\\\\Administrator\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.4.0\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"C:\\\\Users\\\\Administrator\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_linux-2.2.1\\\\","native_build":false,"dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"C:\\\\Users\\\\Administrator\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_windows-2.3.0\\\\","native_build":false,"dependencies":[]}],"web":[]},"dependencyGraph":[{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]}],"date_created":"2024-08-20 16:40:54.130946","version":"3.24.0","swift_package_manager_enabled":false} \ No newline at end of file +{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"path_provider_foundation","path":"C:\\\\Users\\\\Administrator\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.4.0\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"android":[{"name":"path_provider_android","path":"C:\\\\Users\\\\Administrator\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_android-2.2.10\\\\","native_build":true,"dependencies":[]}],"macos":[{"name":"path_provider_foundation","path":"C:\\\\Users\\\\Administrator\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_foundation-2.4.0\\\\","shared_darwin_source":true,"native_build":true,"dependencies":[]}],"linux":[{"name":"path_provider_linux","path":"C:\\\\Users\\\\Administrator\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_linux-2.2.1\\\\","native_build":false,"dependencies":[]}],"windows":[{"name":"path_provider_windows","path":"C:\\\\Users\\\\Administrator\\\\AppData\\\\Local\\\\Pub\\\\Cache\\\\hosted\\\\pub.dev\\\\path_provider_windows-2.3.0\\\\","native_build":false,"dependencies":[]}],"web":[]},"dependencyGraph":[{"name":"path_provider","dependencies":["path_provider_android","path_provider_foundation","path_provider_linux","path_provider_windows"]},{"name":"path_provider_android","dependencies":[]},{"name":"path_provider_foundation","dependencies":[]},{"name":"path_provider_linux","dependencies":[]},{"name":"path_provider_windows","dependencies":[]}],"date_created":"2024-08-21 11:28:19.723327","version":"3.24.0","swift_package_manager_enabled":false} \ No newline at end of file diff --git a/lib/pages/pass_track/iconContainer.dart b/lib/pages/pass_track/iconContainer.dart index da818b3..689eea9 100644 --- a/lib/pages/pass_track/iconContainer.dart +++ b/lib/pages/pass_track/iconContainer.dart @@ -1,6 +1,10 @@ import 'package:cpnav/pages/pass_track/view.dart'; import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; +import 'package:get/get.dart'; +import 'package:scence_map/controller.dart'; + +ScenceMapController mapController = Get.put(ScenceMapController()); class IconContainer extends StatefulWidget { @override @@ -10,22 +14,35 @@ class IconContainer extends StatefulWidget { class _IconContainerState extends State { final Map _iconColors = { Icons.article: Colors.green, - Icons.speed: Colors.green, - Icons.thermostat: Colors.green, - Icons.zoom_in: Colors.green, - Icons.zoom_out: Colors.green, - Icons.refresh: Colors.green, - Icons.place: Colors.green, + Icons.speed: const Color.fromARGB(255, 166, 182, 149), + Icons.thermostat: const Color.fromARGB(255, 166, 182, 149), + Icons.zoom_in: const Color.fromARGB(255, 166, 182, 149), + Icons.zoom_out: const Color.fromARGB(255, 166, 182, 149), + Icons.refresh: const Color.fromARGB(255, 166, 182, 149), + Icons.place: const Color.fromARGB(255, 166, 182, 149), }; + IconData? _selectedIcon; - void _handleTap(IconData icon, VoidCallback onTap) { + void _handleTap1(IconData icon, VoidCallback onTap) { setState(() { - _iconColors[icon] = const Color.fromARGB(255, 166, 182, 149); // 点击后变浅的颜色 + _selectedIcon = icon; + _iconColors.forEach((key, value) { + _iconColors[key] = key == icon + ? Colors.green // 点击后变浅的颜色 + : const Color.fromARGB(255, 166, 182, 149); // 其他图标恢复原色 + }); + }); + onTap(); + } + + void _handleTap2(IconData icon, VoidCallback onTap) { + setState(() { + _iconColors[icon] = Colors.green; // 点击后变浅的颜色 }); onTap(); Future.delayed(Duration(milliseconds: 200), () { setState(() { - _iconColors[icon] = Colors.green; // 恢复原色 + _iconColors[icon] = const Color.fromARGB(255, 166, 182, 149); // 恢复原色 }); }); } @@ -41,7 +58,7 @@ class _IconContainerState extends State { mainAxisSize: MainAxisSize.min, children: [ Container( - width: 36, + width: 42, decoration: BoxDecoration( color: Colors.transparent, border: Border.all( @@ -52,27 +69,53 @@ class _IconContainerState extends State { ), child: Column( children: [ - _buildIcon(Icons.article, () { + _singleChange(Icons.article, () {}), + _singleChange(Icons.speed, () { + // 处理 speed 图标的点击事件 + }), + _singleChange(Icons.thermostat, () { + // 处理 thermostat 图标的点击事件 + }), + _automChange(Icons.zoom_in, () { + mapcontroller.scale = mapcontroller.scale * 0.5; + if (mapcontroller.scale < 0.2) { + mapcontroller.scale = 0.2; + const snackBar = SnackBar( + content: Text("当前已到放大比例极限"), + backgroundColor: Colors.red, + duration: Duration(seconds: 1), + ); + + ScaffoldMessenger.of(context).showSnackBar(snackBar); + } + + mapcontroller.rotation.value = 0.0; + mapcontroller.updateCount.value++; + }), + _automChange(Icons.zoom_out, () { + mapcontroller.scale = mapcontroller.scale / 0.5; + + if (mapcontroller.scale > 200) { + mapcontroller.scale = 200; + // 提示最大比例 + const snackBar = SnackBar( + content: Text("当前已到缩小比例极限"), + backgroundColor: Colors.red, + duration: Duration(seconds: 1), + ); + + ScaffoldMessenger.of(context).showSnackBar(snackBar); + } + + mapcontroller.rotation.value = 0.0; + mapcontroller.updateCount.value++; + }), + _automChange(Icons.refresh, () { mapcontroller.scale = 1.0; mapcontroller.rotation.value = 0.0; mapcontroller.updateCount.value++; }), - _buildIcon(Icons.speed, () { - // 处理 speed 图标的点击事件 - }), - _buildIcon(Icons.thermostat, () { - // 处理 thermostat 图标的点击事件 - }), - _buildIcon(Icons.zoom_in, () { - // 处理 zoom_in 图标的点击事件 - }), - _buildIcon(Icons.zoom_out, () { - // 处理 zoom_out 图标的点击事件 - }), - _buildIcon(Icons.refresh, () { - // 处理 refresh 图标的点击事件 - }), - _buildIcon(Icons.place, () { + _automChange(Icons.place, () { // 处理 place 图标的点击事件 }), ], @@ -87,7 +130,7 @@ class _IconContainerState extends State { mainAxisSize: MainAxisSize.min, children: [ Container( - height: 36, + height: 42, decoration: BoxDecoration( color: Colors.transparent, border: Border.all( @@ -98,27 +141,57 @@ class _IconContainerState extends State { ), child: Row( children: [ - _buildIcon(Icons.article, () { + _singleChange(Icons.article, () { mapcontroller.scale = 1.0; mapcontroller.rotation.value = 0.0; mapcontroller.updateCount.value++; }), - _buildIcon(Icons.speed, () { + _singleChange(Icons.speed, () { // 处理 speed 图标的点击事件 }), - _buildIcon(Icons.thermostat, () { + _singleChange(Icons.thermostat, () { // 处理 thermostat 图标的点击事件 }), - _buildIcon(Icons.zoom_in, () { - // 处理 zoom_in 图标的点击事件 + _automChange(Icons.zoom_in, () { + mapcontroller.scale = mapcontroller.scale * 0.5; + if (mapcontroller.scale < 0.2) { + mapcontroller.scale = 0.2; + const snackBar = SnackBar( + content: Text("当前已到放大比例极限"), + backgroundColor: Colors.red, + duration: Duration(seconds: 1), + ); + + ScaffoldMessenger.of(context).showSnackBar(snackBar); + } + + mapcontroller.rotation.value = 0.0; + mapcontroller.updateCount.value++; }), - _buildIcon(Icons.zoom_out, () { - // 处理 zoom_out 图标的点击事件 + _automChange(Icons.zoom_out, () { + mapcontroller.scale = mapcontroller.scale / 0.5; + + if (mapcontroller.scale > 200) { + mapcontroller.scale = 200; + // 提示最大比例 + const snackBar = SnackBar( + content: Text("当前已到缩小比例极限"), + backgroundColor: Colors.red, + duration: Duration(seconds: 1), + ); + + ScaffoldMessenger.of(context).showSnackBar(snackBar); + } + + mapcontroller.rotation.value = 0.0; + mapcontroller.updateCount.value++; }), - _buildIcon(Icons.refresh, () { - // 处理 refresh 图标的点击事件 + _automChange(Icons.refresh, () { + mapcontroller.scale = 1.0; + mapcontroller.rotation.value = 0.0; + mapcontroller.updateCount.value++; }), - _buildIcon(Icons.place, () { + _automChange(Icons.place, () { // 处理 place 图标的点击事件 }), ], @@ -128,10 +201,11 @@ class _IconContainerState extends State { )); } - Widget _buildIcon(IconData icon, VoidCallback onTap) { + //前三个单选 + Widget _singleChange(IconData icon, VoidCallback onTap) { return Container( - width: 30, - height: 30, + width: 33, + height: 33, margin: EdgeInsets.symmetric(vertical: 2.0), decoration: BoxDecoration( color: _iconColors[icon], @@ -145,9 +219,31 @@ class _IconContainerState extends State { icon, color: Colors.white, ), - onTap: () => _handleTap(icon, onTap), + onTap: () => _handleTap1(icon, onTap), + ), + ); + } + + //后三个自动恢复 + Widget _automChange(IconData icon, VoidCallback onTap) { + return Container( + width: 33, + height: 33, + margin: EdgeInsets.symmetric(vertical: 2.0), + decoration: BoxDecoration( + color: _iconColors[icon], + border: Border.all( + color: Colors.white, + ), + borderRadius: BorderRadius.circular(5.0), + ), + child: InkWell( + child: Icon( + icon, + color: Colors.white, + ), + onTap: () => _handleTap2(icon, onTap), ), ); } } - diff --git a/lib/pages/pass_track/view.dart b/lib/pages/pass_track/view.dart index df2c0a1..26477a7 100644 --- a/lib/pages/pass_track/view.dart +++ b/lib/pages/pass_track/view.dart @@ -7,7 +7,7 @@ import 'package:flutter/widgets.dart'; import 'package:get/get.dart'; import 'package:scence_map/controller.dart'; import 'package:scence_map/scence_map.dart'; -import 'package:bottom_picker/bottom_picker.dart'; + import 'package:syncfusion_flutter_sliders/sliders.dart'; import 'iconContainer.dart'; import "controller.dart"; @@ -33,6 +33,8 @@ class PassTrack extends StatefulWidget { } class _PasstrackState extends State { + final GlobalKey> _popupMenuKey = + GlobalKey>(); final controller = Get.put(PassTrackController("WXLMB", "cp_orad")); String str = "播放"; int sWidth = 0; @@ -109,7 +111,7 @@ class _PasstrackState extends State { }, ), Positioned( - width: isPortrait ? size.width * .63 : size.width * .42, + width: isPortrait ? size.width * .63 : size.width * .41, left: isPortrait ? 190 : 200, bottom: 30, child: Container( @@ -158,45 +160,59 @@ class _PasstrackState extends State { ), ), const SizedBox(width: 5), - Container( - width: 82, - height: 35, - padding: const EdgeInsets.symmetric(horizontal: 1.0), - decoration: BoxDecoration( - color: const Color.fromARGB(255, 255, 255, 255), - border: Border.all(color: Colors.black), - ), - child: Row( - mainAxisSize: MainAxisSize.min, - children: [ - Center( - child: Text( - "$speed X", - style: const TextStyle( - fontSize: 11, color: Colors.black), - ), + 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), ), - PopupMenuButton( - padding: const EdgeInsets.all(1.0), - icon: const Icon(Icons.arrow_drop_up, - color: Color.fromARGB(255, 47, 48, 47)), - onSelected: (int value) { - setState(() { - speed = value; - }); - }, - itemBuilder: (BuildContext context) { - return speedList.map((int speed) { - return PopupMenuItem( - height: 30, - value: speed, - child: Text("$speed X速度"), - ); - }).toList(); - }, - ), - ], - ), + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + Text( + "$speed X", + style: const TextStyle( + fontSize: 11, color: Colors.black), + ), + Container( + width: 25, + child: PopupMenuButton( + 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) { + setState(() { + speed = value; + }); + }, + // style: ButtonStyle( + // minimumSize: MaterialStateProperty.all( + // Size(48, 48)), // 设置最小点击区域 + // tapTargetSize: MaterialTapTargetSize + // .shrinkWrap, // 设置点击区域大小 + // ), + itemBuilder: (BuildContext context) { + return speedList.map((int speed) { + return PopupMenuItem( + height: 30, + value: speed, + child: Text("$speed X速度"), + ); + }).toList(); + }, + ), + ), + ], + )), ), const SizedBox(width: 12), Column(