diff --git a/lib/features/home/presentation/widgets/map/testmap_pages.dart b/lib/features/home/presentation/widgets/map/testmap_pages.dart index 1cdcab48..47d82c86 100644 --- a/lib/features/home/presentation/widgets/map/testmap_pages.dart +++ b/lib/features/home/presentation/widgets/map/testmap_pages.dart @@ -2520,6 +2520,7 @@ class _MapPageEnterpriseState extends State { child: FloatingActionButton( onPressed: _moveToCurrentLocation, child: VerticalFloatMenu( + selectedWorkModeIn: _currentWorkMode ?? WorkMode.bow, onEditTap: (bool isOpen) { setState(() { _isPanelOpen = isOpen; @@ -2545,7 +2546,12 @@ class _MapPageEnterpriseState extends State { }, onWorkModeSelected: (mode) { - _currentWorkMode = mode; + debugPrint('外部收到作业模式选择:$mode'); + setState(() { + _currentWorkMode = mode; + _saveDataToLocal(); + }); + debugPrint('外部收到作业模式:$mode'); }, handleGotoLocation: _handleGotoLocation, @@ -2565,6 +2571,7 @@ class _MapPageEnterpriseState extends State { initialRobotMode: _currentRobotMode, initialAreaMode: _currentAreaMode, initialWorkMode: _currentWorkMode!, + isShowButton: _currentWorkMode == WorkMode.bow ? true : false, canUndo: _isWorkAreaCompleted && _currentAreaMode == AreaMode.work ? false : true, onComplete: () async { debugPrint( diff --git a/lib/features/home/presentation/widgets/path_list_pages.dart b/lib/features/home/presentation/widgets/path_list_pages.dart index 745197c9..4012f6d0 100644 --- a/lib/features/home/presentation/widgets/path_list_pages.dart +++ b/lib/features/home/presentation/widgets/path_list_pages.dart @@ -13,6 +13,9 @@ class VerticalFloatMenu extends StatefulWidget { final VoidCallback? handleGotoLocation; final ValueChanged? onDjShow; + // ===================== 只开放这一个外部传入 ===================== + final WorkMode selectedWorkModeIn; + const VerticalFloatMenu({ super.key, this.onItemTap, @@ -23,6 +26,8 @@ class VerticalFloatMenu extends StatefulWidget { this.onVideoTap, this.handleGotoLocation, this.onDjShow, + // 外部传入,默认值 robot + this.selectedWorkModeIn = WorkMode.bow, }); @override @@ -37,6 +42,27 @@ class _VerticalFloatMenuState extends State { RobotMode _robotMode = RobotMode.point; AreaMode _areaMode = AreaMode.work; + // 用外部传入的值 + late WorkMode _selectedWorkModeIn; + + @override + void didUpdateWidget(covariant VerticalFloatMenu oldWidget) { + super.didUpdateWidget(oldWidget); + // 外部传入的 selectedWorkModeIn 变化时,内部同步更新 + if (oldWidget.selectedWorkModeIn != widget.selectedWorkModeIn) { + setState(() { + _selectedWorkModeIn = widget.selectedWorkModeIn; + }); + } + } + + @override + void initState() { + super.initState(); + // 初始化:取外部传进来的值 + _selectedWorkModeIn = widget.selectedWorkModeIn; + } + final List> _menuItems = const [ {"icon": Icons.crop_free, "name": "圈地"}, {"icon": Icons.format_list_bulleted, "name": "列表"}, @@ -68,7 +94,7 @@ class _VerticalFloatMenuState extends State { widget.onItemTap?.call(index, name); //圈地 if (index == 0) { - final result = await _showModeDialog(); + final result = await _showModeDialog(_selectedWorkModeIn); if (result != null) { _selectedWorkMode = result; @@ -125,8 +151,9 @@ class _VerticalFloatMenuState extends State { /// ================= 弹窗 ================= - Future _showModeDialog() { - WorkMode selectedMode = WorkMode.bow; + Future _showModeDialog(_selectedWorkModeIn) { + WorkMode selectedMode = _selectedWorkModeIn; + debugPrint("打开模式选择弹窗,当前选中模式:$selectedMode,$_selectedWorkModeIn"); return showDialog( context: context, diff --git a/lib/features/home/presentation/widgets/startpoint_area.dart b/lib/features/home/presentation/widgets/startpoint_area.dart index fd4698c6..c79a4e44 100644 --- a/lib/features/home/presentation/widgets/startpoint_area.dart +++ b/lib/features/home/presentation/widgets/startpoint_area.dart @@ -10,6 +10,7 @@ class BottomOperationPanel extends StatefulWidget { // 新增:外部控制初始选中的标签(默认地块) final String initialSelectedTab; final WorkMode initialWorkMode; + final bool isShowButton; //是否显示地块航线 final bool? canUndo; // 是否可以撤回(控制撤回按钮状态) // 回调函数:向外部传递事件 final VoidCallback onComplete; // 完成按钮点击回调 @@ -32,6 +33,7 @@ class BottomOperationPanel extends StatefulWidget { this.initialAreaMode = AreaMode.work, this.initialSelectedTab = '地块', // 默认选中地块 this.initialWorkMode = WorkMode.bow, + this.isShowButton = true, required this.onComplete, // 完成按钮必须传 this.onRobotModeChanged, this.onAreaModeChanged, @@ -85,51 +87,52 @@ class _BottomOperationPanelState extends State { children: [ _buildTabContent(), // 底部标签页切换(修复背景色切换+状态更新) - Container( - decoration: BoxDecoration(color: Colors.grey[200], borderRadius: BorderRadius.circular(8)), - child: Row( - children: [ - Expanded( - child: GestureDetector( - onTap: () { - setState(() { - _currentTab = '地块'; // 更新选中状态 - }); - debugPrint('切换到地块标签'); - widget.onLandTap?.call(); - }, - child: Container( - padding: const EdgeInsets.symmetric(vertical: 10), - // 选中地块时背景为白色,否则透明 - decoration: BoxDecoration(color: _currentTab == '地块' ? Colors.white : Colors.transparent, borderRadius: BorderRadius.circular(8)), - child: const Center( - child: Text('地块', style: TextStyle(color: Colors.black87, fontSize: 16)), + if (widget.isShowButton) + Container( + decoration: BoxDecoration(color: Colors.grey[200], borderRadius: BorderRadius.circular(8)), + child: Row( + children: [ + Expanded( + child: GestureDetector( + onTap: () { + setState(() { + _currentTab = '地块'; // 更新选中状态 + }); + debugPrint('切换到地块标签'); + widget.onLandTap?.call(); + }, + child: Container( + padding: const EdgeInsets.symmetric(vertical: 10), + // 选中地块时背景为白色,否则透明 + decoration: BoxDecoration(color: _currentTab == '地块' ? Colors.white : Colors.transparent, borderRadius: BorderRadius.circular(8)), + child: const Center( + child: Text('地块', style: TextStyle(color: Colors.black87, fontSize: 16)), + ), ), ), ), - ), - Expanded( - child: GestureDetector( - onTap: () { - setState(() { - _currentTab = '航线'; // 更新选中状态 - }); - debugPrint('切换到航线标签'); - widget.onRouteTap?.call(); - }, - child: Container( - padding: const EdgeInsets.symmetric(vertical: 10), - // 选中航线时背景为白色,否则透明 - decoration: BoxDecoration(color: _currentTab == '航线' ? Colors.white : Colors.transparent, borderRadius: BorderRadius.circular(8)), - child: const Center( - child: Text('航线', style: TextStyle(color: Colors.black87, fontSize: 16)), + Expanded( + child: GestureDetector( + onTap: () { + setState(() { + _currentTab = '航线'; // 更新选中状态 + }); + debugPrint('切换到航线标签'); + widget.onRouteTap?.call(); + }, + child: Container( + padding: const EdgeInsets.symmetric(vertical: 10), + // 选中航线时背景为白色,否则透明 + decoration: BoxDecoration(color: _currentTab == '航线' ? Colors.white : Colors.transparent, borderRadius: BorderRadius.circular(8)), + child: const Center( + child: Text('航线', style: TextStyle(color: Colors.black87, fontSize: 16)), + ), ), ), ), - ), - ], + ], + ), ), - ), const SizedBox(height: 5), ], ),