优化 自定义模式不显示航线选项 自定义模式显示和弓子显示的默认选择从缓存获取
This commit is contained in:
@@ -2520,6 +2520,7 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
child: FloatingActionButton(
|
||||
onPressed: _moveToCurrentLocation,
|
||||
child: VerticalFloatMenu(
|
||||
selectedWorkModeIn: _currentWorkMode ?? WorkMode.bow,
|
||||
onEditTap: (bool isOpen) {
|
||||
setState(() {
|
||||
_isPanelOpen = isOpen;
|
||||
@@ -2545,7 +2546,12 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
},
|
||||
|
||||
onWorkModeSelected: (mode) {
|
||||
_currentWorkMode = mode;
|
||||
debugPrint('外部收到作业模式选择:$mode');
|
||||
setState(() {
|
||||
_currentWorkMode = mode;
|
||||
_saveDataToLocal();
|
||||
});
|
||||
|
||||
debugPrint('外部收到作业模式:$mode');
|
||||
},
|
||||
handleGotoLocation: _handleGotoLocation,
|
||||
@@ -2565,6 +2571,7 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
initialRobotMode: _currentRobotMode,
|
||||
initialAreaMode: _currentAreaMode,
|
||||
initialWorkMode: _currentWorkMode!,
|
||||
isShowButton: _currentWorkMode == WorkMode.bow ? true : false,
|
||||
canUndo: _isWorkAreaCompleted && _currentAreaMode == AreaMode.work ? false : true,
|
||||
onComplete: () async {
|
||||
debugPrint(
|
||||
|
||||
@@ -13,6 +13,9 @@ class VerticalFloatMenu extends StatefulWidget {
|
||||
final VoidCallback? handleGotoLocation;
|
||||
final ValueChanged<bool>? 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<VerticalFloatMenu> {
|
||||
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<Map<String, dynamic>> _menuItems = const [
|
||||
{"icon": Icons.crop_free, "name": "圈地"},
|
||||
{"icon": Icons.format_list_bulleted, "name": "列表"},
|
||||
@@ -68,7 +94,7 @@ class _VerticalFloatMenuState extends State<VerticalFloatMenu> {
|
||||
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<VerticalFloatMenu> {
|
||||
|
||||
/// ================= 弹窗 =================
|
||||
|
||||
Future<WorkMode?> _showModeDialog() {
|
||||
WorkMode selectedMode = WorkMode.bow;
|
||||
Future<WorkMode?> _showModeDialog(_selectedWorkModeIn) {
|
||||
WorkMode selectedMode = _selectedWorkModeIn;
|
||||
debugPrint("打开模式选择弹窗,当前选中模式:$selectedMode,$_selectedWorkModeIn");
|
||||
|
||||
return showDialog<WorkMode>(
|
||||
context: context,
|
||||
|
||||
@@ -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<BottomOperationPanel> {
|
||||
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),
|
||||
],
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user