开始作业 暂停停止的UI
This commit is contained in:
@@ -11,3 +11,9 @@ enum WorkMode {
|
||||
enum RobotMode { point, robot }
|
||||
|
||||
enum AreaMode { work, obstacle }
|
||||
|
||||
enum WorkStatus {
|
||||
idle, // 未开始
|
||||
working, // 作业中
|
||||
paused, // 暂停中
|
||||
}
|
||||
|
||||
@@ -71,6 +71,7 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
// 初始化轨迹管理器(泛型指定为LatLng)
|
||||
late final TracePoint<PlotPoint> _traceManager;
|
||||
late String workMode = "弓字模式"; // 作业模式:默认值为"弓字模式"
|
||||
WorkStatus _workStatus = WorkStatus.idle;
|
||||
|
||||
LatLng? _currentLatLng;
|
||||
StreamSubscription<Position>? _positionSub;
|
||||
@@ -917,6 +918,50 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
);
|
||||
}
|
||||
|
||||
/// 开始作业
|
||||
void _startWork() {
|
||||
if (gcjPathPoints.isEmpty) return;
|
||||
|
||||
setState(() {
|
||||
_workStatus = WorkStatus.working;
|
||||
});
|
||||
|
||||
debugPrint('开始作业:${_selectedPlot!.plotName},路径数据:$gcjPathPoints');
|
||||
|
||||
// 可选:显示作业提示
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('作业已开始'), backgroundColor: Colors.green));
|
||||
}
|
||||
|
||||
/// 暂停作业
|
||||
void _pauseWork() {
|
||||
setState(() {
|
||||
_workStatus = WorkStatus.paused;
|
||||
});
|
||||
|
||||
// 模拟暂停逻辑(替换为你的实际暂停代码)
|
||||
debugPrint('暂停作业:${_selectedPlot!.plotName}');
|
||||
|
||||
// 可选:显示暂停提示
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('作业已暂停'), backgroundColor: Colors.amber));
|
||||
}
|
||||
|
||||
void _stopWork() {
|
||||
setState(() {
|
||||
_workStatus = WorkStatus.idle;
|
||||
});
|
||||
// 模拟停止逻辑(替换为你的实际停止代码)
|
||||
debugPrint('停止作业:${_selectedPlot!.plotName}');
|
||||
// 可选:显示停止提示
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('作业已停止'), backgroundColor: Colors.redAccent));
|
||||
}
|
||||
|
||||
/// 继续作业
|
||||
void _resumeWork() {
|
||||
setState(() {
|
||||
_workStatus = WorkStatus.working;
|
||||
});
|
||||
}
|
||||
|
||||
void _showDeleteConfirmDialog(PlotData plot, Function(PlotData) onDelete) {
|
||||
ConfirmDialog.show(
|
||||
context: context,
|
||||
@@ -926,9 +971,6 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
confirmTextColor: Colors.red,
|
||||
onConfirm: () {
|
||||
onDelete(plot);
|
||||
if (context.mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text('已删除地块「${plot.plotName}」')));
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
@@ -1037,29 +1079,103 @@ class _MapPageEnterpriseState extends State<MapPageEnterprise> {
|
||||
),
|
||||
|
||||
// 3. 开始作业按钮(加载中禁用)
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
height: 50,
|
||||
child: ElevatedButton(
|
||||
onPressed: state.isLoading || gcjPathPoints.isEmpty
|
||||
? null
|
||||
: () {
|
||||
// 作业逻辑:使用加载的pathData
|
||||
debugPrint('开始作业:${_selectedPlot!.plotName},路径数据:$gcjPathPoints');
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF00C853),
|
||||
foregroundColor: Colors.white,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
|
||||
elevation: 2,
|
||||
disabledBackgroundColor: Colors.grey[300],
|
||||
disabledForegroundColor: Colors.grey[600],
|
||||
),
|
||||
child: state.isLoading
|
||||
? const SizedBox(width: 20, height: 20, child: CircularProgressIndicator(strokeWidth: 2, color: Colors.white))
|
||||
: const Text('开始作业', style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold)),
|
||||
),
|
||||
),
|
||||
// 放在 Column/Row 的 children: [ ... ] 内部
|
||||
_workStatus == WorkStatus.idle
|
||||
? SizedBox(
|
||||
width: double.infinity,
|
||||
height: 50,
|
||||
child: ElevatedButton(
|
||||
onPressed: state.isLoading || gcjPathPoints.isEmpty
|
||||
? null
|
||||
: () {
|
||||
// 开始作业逻辑
|
||||
_startWork();
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF00C853),
|
||||
foregroundColor: Colors.white,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
|
||||
elevation: 2,
|
||||
disabledBackgroundColor: Colors.grey[300],
|
||||
disabledForegroundColor: Colors.grey[600],
|
||||
),
|
||||
child: state.isLoading
|
||||
? const SizedBox(width: 20, height: 20, child: CircularProgressIndicator(strokeWidth: 2, color: Colors.white))
|
||||
: const Text('开始作业', style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold)),
|
||||
),
|
||||
)
|
||||
: Row(
|
||||
children: [
|
||||
// 暂停/继续图标按钮
|
||||
Expanded(
|
||||
child: SizedBox(
|
||||
width: 50,
|
||||
height: 50,
|
||||
child: ElevatedButton(
|
||||
onPressed: () => _workStatus == WorkStatus.working ? _pauseWork() : _resumeWork(),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: _workStatus == WorkStatus.working ? Colors.amber : const Color(0xFF00C853),
|
||||
foregroundColor: Colors.white,
|
||||
shape: const CircleBorder(),
|
||||
elevation: 2,
|
||||
// 调整内边距,让图标居中更协调
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
),
|
||||
child: Icon(
|
||||
// 作业中显示暂停图标,暂停中显示播放(继续)图标
|
||||
_workStatus == WorkStatus.working ? Icons.pause : Icons.play_arrow,
|
||||
size: 24, // 图标尺寸
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
// 停止图标按钮
|
||||
Expanded(
|
||||
child: SizedBox(
|
||||
width: 50,
|
||||
height: 50,
|
||||
child: ElevatedButton(
|
||||
onPressed: () => _stopWork(),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.redAccent,
|
||||
foregroundColor: Colors.white,
|
||||
shape: const CircleBorder(),
|
||||
elevation: 2,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
||||
),
|
||||
child: const Icon(
|
||||
Icons.stop, // 停止图标(也可以用 Icons.close)
|
||||
size: 24,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
//SizedBox(
|
||||
// width: double.infinity,
|
||||
// height: 50,
|
||||
// child: ElevatedButton(
|
||||
// onPressed: state.isLoading || gcjPathPoints.isEmpty
|
||||
// ? null
|
||||
// : () {
|
||||
// // 作业逻辑:使用加载的pathData
|
||||
// debugPrint('开始作业:${_selectedPlot!.plotName},路径数据:$gcjPathPoints');
|
||||
// },
|
||||
// style: ElevatedButton.styleFrom(
|
||||
// backgroundColor: const Color(0xFF00C853),
|
||||
// foregroundColor: Colors.white,
|
||||
// shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
|
||||
// elevation: 2,
|
||||
// disabledBackgroundColor: Colors.grey[300],
|
||||
// disabledForegroundColor: Colors.grey[600],
|
||||
// ),
|
||||
// child: state.isLoading
|
||||
// ? const SizedBox(width: 20, height: 20, child: CircularProgressIndicator(strokeWidth: 2, color: Colors.white))
|
||||
// : const Text('开始作业', style: TextStyle(fontSize: 14, fontWeight: FontWeight.bold)),
|
||||
// ),
|
||||
//),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user