完善遥控权限、控制发送和急停反馈
This commit is contained in:
@@ -7,6 +7,7 @@ import '../../../../core/localization/app_localizations.dart';
|
||||
import '../../domain/entities/device_control_mode.dart';
|
||||
import '../../domain/usecases/device_control_mode_usecases.dart';
|
||||
import '../cubit/control_mode_entry_cubit.dart';
|
||||
import 'mode_independent_control.dart';
|
||||
|
||||
Future<bool> showControlModeEntryDialog(
|
||||
BuildContext context, {
|
||||
@@ -15,6 +16,7 @@ Future<bool> showControlModeEntryDialog(
|
||||
String? deviceName,
|
||||
bool allowTargetSelection = false,
|
||||
bool cancelToPreview = false,
|
||||
Widget? emergencyStopControl,
|
||||
ControlModeEntryCubit? cubit,
|
||||
}) async {
|
||||
final entry =
|
||||
@@ -34,6 +36,7 @@ Future<bool> showControlModeEntryDialog(
|
||||
backgroundColor: Colors.transparent,
|
||||
barrierColor: const Color(0x8C0B1B2B),
|
||||
isScrollControlled: true,
|
||||
constraints: const BoxConstraints(maxWidth: 440),
|
||||
isDismissible: false,
|
||||
enableDrag: false,
|
||||
builder: (_) => BlocProvider.value(
|
||||
@@ -42,6 +45,7 @@ Future<bool> showControlModeEntryDialog(
|
||||
deviceName: deviceName,
|
||||
allowTargetSelection: allowTargetSelection,
|
||||
cancelToPreview: cancelToPreview,
|
||||
emergencyStopControl: emergencyStopControl,
|
||||
),
|
||||
),
|
||||
) ??
|
||||
@@ -61,6 +65,7 @@ class ControlModeEntryGate extends StatefulWidget {
|
||||
this.deviceName,
|
||||
this.onReady,
|
||||
this.cancelToPreview = false,
|
||||
this.emergencyStopControl,
|
||||
});
|
||||
final String deviceId;
|
||||
final String? deviceName;
|
||||
@@ -68,6 +73,9 @@ class ControlModeEntryGate extends StatefulWidget {
|
||||
final Widget child;
|
||||
final VoidCallback? onReady;
|
||||
final bool cancelToPreview;
|
||||
|
||||
/// 独立急停链路,不受控制模式确认限制。
|
||||
final Widget? emergencyStopControl;
|
||||
@override
|
||||
State<ControlModeEntryGate> createState() => _ControlModeEntryGateState();
|
||||
}
|
||||
@@ -93,6 +101,7 @@ class _ControlModeEntryGateState extends State<ControlModeEntryGate> {
|
||||
deviceName: widget.deviceName,
|
||||
target: widget.target,
|
||||
cancelToPreview: widget.cancelToPreview,
|
||||
emergencyStopControl: widget.emergencyStopControl,
|
||||
);
|
||||
if (!mounted) return;
|
||||
if (accepted) {
|
||||
@@ -115,7 +124,7 @@ class _ControlModeEntryGateState extends State<ControlModeEntryGate> {
|
||||
children: [
|
||||
ExcludeFocus(
|
||||
excluding: !_ready,
|
||||
child: IgnorePointer(ignoring: !_ready, child: widget.child),
|
||||
child: ControlModePointerGate(blocked: !_ready, child: widget.child),
|
||||
),
|
||||
if (_cancelled && widget.cancelToPreview)
|
||||
_buildPreviewControls(context)
|
||||
@@ -208,6 +217,7 @@ class _ControlModeEntryDialog extends StatelessWidget {
|
||||
this.deviceName,
|
||||
this.allowTargetSelection = false,
|
||||
this.cancelToPreview = false,
|
||||
this.emergencyStopControl,
|
||||
});
|
||||
|
||||
static const _navy = Color(0xFF1A2B4A);
|
||||
@@ -220,6 +230,7 @@ class _ControlModeEntryDialog extends StatelessWidget {
|
||||
final String? deviceName;
|
||||
final bool allowTargetSelection;
|
||||
final bool cancelToPreview;
|
||||
final Widget? emergencyStopControl;
|
||||
|
||||
Widget _modeCard({
|
||||
required String label,
|
||||
@@ -228,7 +239,7 @@ class _ControlModeEntryDialog extends StatelessWidget {
|
||||
bool target = false,
|
||||
}) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(14),
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: target ? _softBlue : const Color(0xFFF6FAFE),
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
@@ -237,15 +248,15 @@ class _ControlModeEntryDialog extends StatelessWidget {
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
width: 30,
|
||||
height: 30,
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Icon(icon, color: _blue, size: 21),
|
||||
child: Icon(icon, color: _blue, size: 18),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@@ -258,7 +269,7 @@ class _ControlModeEntryDialog extends StatelessWidget {
|
||||
Text(
|
||||
value,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w700,
|
||||
color: _navy,
|
||||
),
|
||||
@@ -341,7 +352,7 @@ class _ControlModeEntryDialog extends StatelessWidget {
|
||||
child: SafeArea(
|
||||
top: false,
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.fromLTRB(18, 16, 18, 16),
|
||||
padding: const EdgeInsets.fromLTRB(16, 10, 16, 12),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
@@ -354,12 +365,14 @@ class _ControlModeEntryDialog extends StatelessWidget {
|
||||
allowTargetSelection ? 'switch_title' : 'title',
|
||||
),
|
||||
style: const TextStyle(
|
||||
fontSize: 20,
|
||||
fontSize: 17,
|
||||
fontWeight: FontWeight.w800,
|
||||
color: _navy,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (emergencyStopControl != null)
|
||||
emergencyStopControl!,
|
||||
IconButton(
|
||||
tooltip: cancelToPreview
|
||||
? cancelText
|
||||
@@ -392,27 +405,37 @@ class _ControlModeEntryDialog extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_modeCard(
|
||||
label: tr('current'),
|
||||
value: controlModeDisplayText(
|
||||
l10n,
|
||||
state.reading?.rawMode,
|
||||
),
|
||||
icon: Icons.sensors_rounded,
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
// 自主任务选项继续停用,由后端处理;这里展示本次确认的目标。
|
||||
_modeCard(
|
||||
label: tr(
|
||||
allowTargetSelection ? 'selection_target' : 'target',
|
||||
),
|
||||
value:
|
||||
allowTargetSelection &&
|
||||
cubit.target == ControlModeTarget.remote
|
||||
? tr('switch_manual')
|
||||
: targetText,
|
||||
icon: Icons.swap_horiz_rounded,
|
||||
target: true,
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: _modeCard(
|
||||
label: tr('current'),
|
||||
value: controlModeDisplayText(
|
||||
l10n,
|
||||
state.reading?.rawMode,
|
||||
),
|
||||
icon: Icons.sensors_rounded,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: _modeCard(
|
||||
label: tr(
|
||||
allowTargetSelection
|
||||
? 'selection_target'
|
||||
: 'target',
|
||||
),
|
||||
value:
|
||||
allowTargetSelection &&
|
||||
cubit.target == ControlModeTarget.remote
|
||||
? tr('switch_manual')
|
||||
: targetText,
|
||||
icon: Icons.swap_horiz_rounded,
|
||||
target: true,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Container(
|
||||
@@ -438,7 +461,9 @@ class _ControlModeEntryDialog extends StatelessWidget {
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
note,
|
||||
cubit.target == ControlModeTarget.remote
|
||||
? '$note\n${tr('remote_retry_hint')}'
|
||||
: note,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
height: 1.5,
|
||||
@@ -478,7 +503,7 @@ class _ControlModeEntryDialog extends StatelessWidget {
|
||||
style: TextButton.styleFrom(foregroundColor: _blue),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 18),
|
||||
const SizedBox(height: 12),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
@@ -487,7 +512,7 @@ class _ControlModeEntryDialog extends StatelessWidget {
|
||||
icon: const Icon(Icons.close_rounded, size: 18),
|
||||
style: OutlinedButton.styleFrom(
|
||||
foregroundColor: _blue,
|
||||
minimumSize: const Size.fromHeight(48),
|
||||
minimumSize: const Size.fromHeight(40),
|
||||
side: BorderSide(
|
||||
color: canCancel ? _blue : _border,
|
||||
width: 1.2,
|
||||
@@ -516,7 +541,7 @@ class _ControlModeEntryDialog extends StatelessWidget {
|
||||
0xFFDCEBFA,
|
||||
),
|
||||
disabledForegroundColor: _gray,
|
||||
minimumSize: const Size.fromHeight(48),
|
||||
minimumSize: const Size.fromHeight(40),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
import 'package:flutter/rendering.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
/// 保持控件原位,标记独立于模式确认的操作区(如急停、页面设置)。
|
||||
class ModeIndependentControl extends SingleChildRenderObjectWidget {
|
||||
const ModeIndependentControl({super.key, required super.child});
|
||||
|
||||
@override
|
||||
RenderProxyBox createRenderObject(BuildContext context) =>
|
||||
_IndependentRegion();
|
||||
}
|
||||
|
||||
class _IndependentRegion extends RenderProxyBox {}
|
||||
|
||||
/// 模式未确认时,只将指针事件交给原布局中明确标记的独立操作区。
|
||||
class ControlModePointerGate extends SingleChildRenderObjectWidget {
|
||||
const ControlModePointerGate({
|
||||
super.key,
|
||||
required this.blocked,
|
||||
required super.child,
|
||||
});
|
||||
final bool blocked;
|
||||
|
||||
@override
|
||||
RenderProxyBox createRenderObject(BuildContext context) =>
|
||||
_PointerGate(blocked);
|
||||
|
||||
@override
|
||||
void updateRenderObject(
|
||||
BuildContext context,
|
||||
covariant _PointerGate renderObject,
|
||||
) {
|
||||
renderObject.blocked = blocked;
|
||||
}
|
||||
}
|
||||
|
||||
class _PointerGate extends RenderProxyBox {
|
||||
_PointerGate(this.blocked);
|
||||
bool blocked;
|
||||
|
||||
@override
|
||||
bool hitTestChildren(BoxHitTestResult result, {required Offset position}) {
|
||||
if (!blocked) return super.hitTestChildren(result, position: position);
|
||||
var hit = false;
|
||||
void visit(RenderObject node) {
|
||||
if (hit) return;
|
||||
if (node is _IndependentRegion && node.attached && node.hasSize) {
|
||||
hit = result.addWithPaintTransform(
|
||||
transform: node.getTransformTo(this),
|
||||
position: position,
|
||||
hitTest: (result, position) =>
|
||||
node.hitTest(result, position: position),
|
||||
);
|
||||
return;
|
||||
}
|
||||
node.visitChildren(visit);
|
||||
}
|
||||
|
||||
final content = child;
|
||||
if (content != null) visit(content);
|
||||
return hit;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user