页面刷新功能
This commit is contained in:
@@ -59,6 +59,7 @@ class MapPageEnterprise extends StatefulWidget {
|
||||
class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
final _dispatcher = sl<NetMessageDispatcher>();
|
||||
late StreamSubscription<RawPacket> _sub;
|
||||
bool _isRefreshing = false; // 新增:页面刷新状态标志
|
||||
|
||||
final MapController _mapController = MapController();
|
||||
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(
|
||||
top: 10,
|
||||
@@ -1111,6 +1221,7 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
_currentWorkMode = mode;
|
||||
debugPrint('外部收到作业模式:$mode');
|
||||
},
|
||||
onRefreshTap: _handleRefresh, // 推荐用局部刷新
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user