作业行距和航线方向实时改变 生成路径完成
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class RouteDirectionPanel extends StatefulWidget {
|
||||
// 重命名为Panel更符合组件语义
|
||||
// 接收外部传入的初始值
|
||||
final bool initialOptimalHeading;
|
||||
final double initialDirection;
|
||||
// 新增:回调函数 - 关闭面板/返回设置结果
|
||||
final ValueChanged<Map<String, dynamic>>? onConfirm;
|
||||
// 🔥 核心修改:新增实时回调(值变更时立即触发)
|
||||
final ValueChanged<Map<String, dynamic>>? onValueChanged;
|
||||
// 取消/关闭面板回调(保留)
|
||||
final VoidCallback? onCancel;
|
||||
|
||||
const RouteDirectionPanel({
|
||||
super.key,
|
||||
this.initialOptimalHeading = true, // 默认开启最优航向
|
||||
this.initialDirection = 0.0, // 默认方向0度
|
||||
this.onConfirm,
|
||||
this.onValueChanged, // 实时值变更回调
|
||||
this.onCancel,
|
||||
});
|
||||
|
||||
@@ -30,11 +30,18 @@ class _RouteDirectionPanelState extends State<RouteDirectionPanel> {
|
||||
super.initState();
|
||||
_optimalHeading = widget.initialOptimalHeading;
|
||||
_direction = widget.initialDirection.clamp(0, 360); // 限制在0-360度
|
||||
|
||||
// 初始化时立即传递一次初始值(可选,保证外部能拿到初始状态)
|
||||
_notifyValueChanged();
|
||||
}
|
||||
|
||||
// 🔥 新增:封装值变更通知逻辑
|
||||
void _notifyValueChanged() {
|
||||
widget.onValueChanged?.call({'optimalHeading': _optimalHeading, 'direction': _direction});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// 纯面板结构:无Scaffold,仅Container包裹核心UI
|
||||
return Container(
|
||||
decoration: const BoxDecoration(
|
||||
color: Colors.white,
|
||||
@@ -42,7 +49,7 @@ class _RouteDirectionPanelState extends State<RouteDirectionPanel> {
|
||||
boxShadow: [BoxShadow(color: Colors.black12, blurRadius: 8)],
|
||||
),
|
||||
padding: const EdgeInsets.all(16),
|
||||
constraints: const BoxConstraints(minHeight: 300), // 最小高度保证UI完整
|
||||
constraints: const BoxConstraints(minHeight: 240), // 最小高度保证UI完整
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
@@ -56,35 +63,22 @@ class _RouteDirectionPanelState extends State<RouteDirectionPanel> {
|
||||
onTap: () {
|
||||
widget.onCancel?.call(); // 触发取消回调
|
||||
},
|
||||
child: const Icon(
|
||||
Icons.arrow_back_ios,
|
||||
color: Colors.black87,
|
||||
size: 20,
|
||||
),
|
||||
child: const Icon(Icons.arrow_back_ios, color: Colors.black87, size: 20),
|
||||
),
|
||||
const Text(
|
||||
'航线方向',
|
||||
style: TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.black87,
|
||||
),
|
||||
style: TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: Colors.black87),
|
||||
),
|
||||
const SizedBox(width: 24), // 占位保持标题居中
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
//const Divider(height: 1, color: Colors.grey),
|
||||
//const SizedBox(height: 20),
|
||||
|
||||
// 最优航向开关
|
||||
// 最优航向开关(修改:值变更时触发回调)
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text(
|
||||
'最优航向',
|
||||
style: TextStyle(fontSize: 16, color: Colors.black87),
|
||||
),
|
||||
const Text('最优航向', style: TextStyle(fontSize: 16, color: Colors.black87)),
|
||||
Switch(
|
||||
value: _optimalHeading,
|
||||
activeColor: const Color(0xFF00C853),
|
||||
@@ -92,30 +86,25 @@ class _RouteDirectionPanelState extends State<RouteDirectionPanel> {
|
||||
setState(() {
|
||||
_optimalHeading = value;
|
||||
});
|
||||
// 🔥 实时传递最新值
|
||||
_notifyValueChanged();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
|
||||
// 航线方向滑块
|
||||
// 航线方向滑块(修改:值变更时触发回调)
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text(
|
||||
'航线方向',
|
||||
style: TextStyle(fontSize: 16, color: Colors.black87),
|
||||
),
|
||||
const Text('航线方向', style: TextStyle(fontSize: 16, color: Colors.black87)),
|
||||
Text(
|
||||
'${_direction.toStringAsFixed(0)}°',
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
color: _optimalHeading ? Colors.grey : Colors.black87,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
style: TextStyle(fontSize: 16, color: _optimalHeading ? Colors.grey : Colors.black87, fontWeight: FontWeight.w500),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -134,34 +123,12 @@ class _RouteDirectionPanelState extends State<RouteDirectionPanel> {
|
||||
setState(() {
|
||||
_direction = value;
|
||||
});
|
||||
// 🔥 实时传递最新值
|
||||
_notifyValueChanged();
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
|
||||
// 确认按钮
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: ElevatedButton(
|
||||
onPressed: () {
|
||||
// 触发确认回调,传递设置结果
|
||||
widget.onConfirm?.call({
|
||||
'optimalHeading': _optimalHeading,
|
||||
'direction': _direction,
|
||||
});
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: const Color(0xFF00C853),
|
||||
foregroundColor: Colors.white,
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
child: const Text('确认'),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user