页面刷新功能
This commit is contained in:
@@ -59,6 +59,7 @@ class MapPageEnterprise extends StatefulWidget {
|
|||||||
class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||||
final _dispatcher = sl<NetMessageDispatcher>();
|
final _dispatcher = sl<NetMessageDispatcher>();
|
||||||
late StreamSubscription<RawPacket> _sub;
|
late StreamSubscription<RawPacket> _sub;
|
||||||
|
bool _isRefreshing = false; // 新增:页面刷新状态标志
|
||||||
|
|
||||||
final MapController _mapController = MapController();
|
final MapController _mapController = MapController();
|
||||||
final TextEditingController _plotNameController = TextEditingController();
|
final TextEditingController _plotNameController = TextEditingController();
|
||||||
@@ -366,6 +367,97 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ========== 新增:页面刷新初始化方法 ==========
|
||||||
|
Future<void> _handleRefresh() async {
|
||||||
|
// 防止重复刷新
|
||||||
|
if (_isRefreshing) return;
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
_isRefreshing = true; // 标记开始刷新
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
// 1. 取消旧的定位监听
|
||||||
|
await _positionSub?.cancel();
|
||||||
|
|
||||||
|
// 2. 重置所有页面状态(恢复初始值)
|
||||||
|
setState(() {
|
||||||
|
// 清空打点和轨迹数据
|
||||||
|
_markedPoints.clear();
|
||||||
|
gcjPathPoints.clear();
|
||||||
|
gcjOuterPoints.clear();
|
||||||
|
_currentTracePoints = null;
|
||||||
|
|
||||||
|
// 重置面板状态
|
||||||
|
_isPanelOpen = false;
|
||||||
|
_directionBoxOpen = false;
|
||||||
|
_isListBoxOpen = false;
|
||||||
|
_isWorkPanelOpen = false;
|
||||||
|
|
||||||
|
// 重置选中状态
|
||||||
|
_selectedPlot = null;
|
||||||
|
_selectedPlotPath = null;
|
||||||
|
|
||||||
|
// 重置作业模式
|
||||||
|
_currentRobotMode = RobotMode.point;
|
||||||
|
_currentAreaMode = AreaMode.work;
|
||||||
|
_currentWorkMode = WorkMode.bow;
|
||||||
|
|
||||||
|
// 重置参数
|
||||||
|
_workDistance = 0.0;
|
||||||
|
_angle = 0.0;
|
||||||
|
_mapCenter = const LatLng(39.9042, 116.4074);
|
||||||
|
_hasMovedOnce = false;
|
||||||
|
_currentLatLng = null;
|
||||||
|
});
|
||||||
|
|
||||||
|
// 3. 重新初始化定位
|
||||||
|
await _initLocationEnterprise();
|
||||||
|
|
||||||
|
// 4. 重置轨迹管理器
|
||||||
|
_traceManager.reset();
|
||||||
|
|
||||||
|
// 5. 重新加载作业记录(保持数据最新)
|
||||||
|
final userId = context.read<AppUserCubit>().state.user?.userId ?? "";
|
||||||
|
if (userId.isNotEmpty) {
|
||||||
|
await context.read<DevicesCubit>().loadWorkRecords(userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 6. 重置地图视角到初始位置
|
||||||
|
_mapController.move(const LatLng(39.9042, 116.4074), 17);
|
||||||
|
|
||||||
|
// 刷新成功提示
|
||||||
|
if (mounted) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(
|
||||||
|
content: Text('页面已刷新完成'),
|
||||||
|
backgroundColor: Colors.green,
|
||||||
|
duration: Duration(seconds: 2),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// 错误处理
|
||||||
|
debugPrint('刷新失败:$e');
|
||||||
|
if (mounted) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text('刷新失败:${e.toString().substring(0, 50)}'),
|
||||||
|
backgroundColor: Colors.red,
|
||||||
|
duration: Duration(seconds: 3),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
// 标记刷新结束
|
||||||
|
if (mounted) {
|
||||||
|
setState(() {
|
||||||
|
_isRefreshing = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// ===============================
|
/// ===============================
|
||||||
/// 更新位置
|
/// 更新位置
|
||||||
/// ===============================
|
/// ===============================
|
||||||
@@ -987,6 +1079,24 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|
||||||
|
if (_isRefreshing)
|
||||||
|
Positioned.fill(
|
||||||
|
child: Container(
|
||||||
|
color: Colors.black.withOpacity(0.3),
|
||||||
|
child: const Center(
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
CircularProgressIndicator(
|
||||||
|
color: Colors.white,
|
||||||
|
strokeWidth: 3,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
// 悬浮返回按钮(核心修改)
|
// 悬浮返回按钮(核心修改)
|
||||||
Positioned(
|
Positioned(
|
||||||
top: 10,
|
top: 10,
|
||||||
@@ -1111,6 +1221,7 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
|||||||
_currentWorkMode = mode;
|
_currentWorkMode = mode;
|
||||||
debugPrint('外部收到作业模式:$mode');
|
debugPrint('外部收到作业模式:$mode');
|
||||||
},
|
},
|
||||||
|
onRefreshTap: _handleRefresh, // 推荐用局部刷新
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ class VerticalFloatMenu extends StatefulWidget {
|
|||||||
final ValueChanged<bool>? onEditTap;
|
final ValueChanged<bool>? onEditTap;
|
||||||
final ValueChanged<bool>? onListBox;
|
final ValueChanged<bool>? onListBox;
|
||||||
final ValueChanged<WorkMode>? onWorkModeSelected;
|
final ValueChanged<WorkMode>? onWorkModeSelected;
|
||||||
|
final VoidCallback? onRefreshTap; // 新增刷新回调
|
||||||
|
|
||||||
const VerticalFloatMenu({
|
const VerticalFloatMenu({
|
||||||
super.key,
|
super.key,
|
||||||
@@ -13,6 +14,7 @@ class VerticalFloatMenu extends StatefulWidget {
|
|||||||
this.onEditTap,
|
this.onEditTap,
|
||||||
this.onListBox,
|
this.onListBox,
|
||||||
this.onWorkModeSelected,
|
this.onWorkModeSelected,
|
||||||
|
this.onRefreshTap, // 接收刷新回调
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -31,7 +33,7 @@ class _VerticalFloatMenuState extends State<VerticalFloatMenu> {
|
|||||||
{"icon": Icons.format_list_bulleted, "name": "列表"},
|
{"icon": Icons.format_list_bulleted, "name": "列表"},
|
||||||
{"icon": Icons.train, "name": "场站"},
|
{"icon": Icons.train, "name": "场站"},
|
||||||
{"icon": Icons.navigation, "name": "定位"},
|
{"icon": Icons.navigation, "name": "定位"},
|
||||||
{"icon": Icons.edit_note, "name": "刷新"},
|
{"icon": Icons.refresh, "name": "刷新"},
|
||||||
{"icon": Icons.videocam, "name": "监控"},
|
{"icon": Icons.videocam, "name": "监控"},
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -81,6 +83,14 @@ class _VerticalFloatMenuState extends State<VerticalFloatMenu> {
|
|||||||
if (index == 1) {
|
if (index == 1) {
|
||||||
widget.onListBox?.call(true);
|
widget.onListBox?.call(true);
|
||||||
}
|
}
|
||||||
|
if (index == 4) {
|
||||||
|
// 触发外部传入的刷新回调
|
||||||
|
widget.onRefreshTap?.call();
|
||||||
|
// 可选:添加刷新动画/状态提示
|
||||||
|
setState(() {
|
||||||
|
// 可以添加刷新中的临时状态(比如图标旋转)
|
||||||
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
width: double.infinity,
|
width: double.infinity,
|
||||||
|
|||||||
Reference in New Issue
Block a user