- 添加 CodeGraph、Android 和通用 gitignore 配置 - 创建项目元数据文件跟踪 Flutter 项目属性 - 添加 Codex AI 指导文档 AGENTS.md 说明项目架构 - 配置代码分析选项 analysis_options.yaml - 设置 Android 应用清单权限和 Kiosk 模式配置 - 实现中英文国际化支持 AppLocalizations - 配置 GoRouter 应用路由导航 - 创建明亮工业控制风格的主题配置 AppTheme
366 lines
12 KiB
Dart
366 lines
12 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import '../../../core/localization/app_localizations.dart';
|
|
import '../../../core/theme/app_theme.dart';
|
|
import '../../../shared/widgets/common_button.dart';
|
|
import '../../device/providers/run_state_provider.dart';
|
|
import '../../programs/providers/programs_provider.dart';
|
|
|
|
/// 运行控制面板 - 暗色工业风格
|
|
/// 显示当前程序信息、瓷套棒状态和运行控制按钮
|
|
class RunningControlPanel extends ConsumerWidget {
|
|
const RunningControlPanel({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
|
final l10n = AppLocalizations.of(context);
|
|
final runState = ref.watch(runStateProvider);
|
|
final programsState = ref.watch(programsProvider);
|
|
|
|
return Container(
|
|
decoration: BoxDecoration(
|
|
color: AppTheme.cardBg,
|
|
borderRadius: BorderRadius.circular(8),
|
|
border: Border.all(color: AppTheme.borderSubtle, width: 1),
|
|
),
|
|
child: runState.status == RunStatus.idle
|
|
? _buildIdleState(context, ref, l10n, programsState.selectedProgram)
|
|
: _buildRunningState(context, ref, l10n, runState),
|
|
);
|
|
}
|
|
|
|
/// 待机状态布局
|
|
Widget _buildIdleState(
|
|
BuildContext context,
|
|
WidgetRef ref,
|
|
AppLocalizations? l10n,
|
|
dynamic selectedProgram,
|
|
) {
|
|
final runNotifier = ref.read(runStateProvider.notifier);
|
|
|
|
return Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
// 当前选中程序显示
|
|
if (selectedProgram != null)
|
|
Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
|
|
decoration: BoxDecoration(
|
|
color: AppTheme.cardSelectedBg,
|
|
borderRadius: BorderRadius.circular(6),
|
|
border: Border.all(color: AppTheme.accentPrimary, width: 1),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
Text(
|
|
'${l10n?.selectedProgramLabel ?? '当前选中'}:',
|
|
style: const TextStyle(
|
|
color: AppTheme.textTertiary,
|
|
fontSize: 12,
|
|
),
|
|
),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: Text(
|
|
'${selectedProgram.code} ${selectedProgram.name}',
|
|
style: const TextStyle(
|
|
color: AppTheme.accentPrimary,
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
)
|
|
else
|
|
Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
|
|
decoration: BoxDecoration(
|
|
color: AppTheme.cardBg,
|
|
borderRadius: BorderRadius.circular(6),
|
|
border: Border.all(color: AppTheme.borderSubtle, width: 1),
|
|
),
|
|
child: Text(
|
|
l10n?.pleaseSelectProgram ?? '请选择要运行的程序',
|
|
style: const TextStyle(
|
|
color: AppTheme.textTertiary,
|
|
fontSize: 12,
|
|
),
|
|
),
|
|
),
|
|
|
|
const SizedBox(height: 12),
|
|
|
|
// 瓷套棒确认提示
|
|
Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 8),
|
|
decoration: BoxDecoration(
|
|
color: AppTheme.cardBg,
|
|
borderRadius: BorderRadius.circular(6),
|
|
border: Border.all(color: AppTheme.borderSubtle, width: 1),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
Container(
|
|
width: 10,
|
|
height: 10,
|
|
decoration: const BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
color: AppTheme.statusStopped,
|
|
),
|
|
),
|
|
const SizedBox(width: 10),
|
|
Expanded(
|
|
child: Text(
|
|
l10n?.ceramicNotInstalled ?? '瓷套棒: 未安装 — 禁止启动',
|
|
style: const TextStyle(
|
|
color: AppTheme.textSecondary,
|
|
fontSize: 12,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
|
|
const SizedBox(height: 12),
|
|
|
|
// 控制按钮
|
|
Row(
|
|
children: [
|
|
// 开始运行按钮
|
|
Expanded(
|
|
flex: 2,
|
|
child: SizedBox(
|
|
height: 48,
|
|
child: CommonButton(
|
|
text: l10n?.startRun ?? '开始运行',
|
|
icon: Icons.play_arrow,
|
|
type: ButtonType.primary,
|
|
enabled: selectedProgram != null,
|
|
onPressed: selectedProgram != null
|
|
? () => runNotifier.start(selectedProgram)
|
|
: null,
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: 12),
|
|
// 暂停/继续按钮(待机态禁用)
|
|
Expanded(
|
|
child: SizedBox(
|
|
height: 48,
|
|
child: CommonButton(
|
|
text: l10n?.pause ?? '暂停',
|
|
icon: Icons.pause,
|
|
type: ButtonType.secondary,
|
|
enabled: false,
|
|
onPressed: null,
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: 12),
|
|
// 停止按钮(待机态禁用)
|
|
Expanded(
|
|
child: SizedBox(
|
|
height: 48,
|
|
child: CommonButton(
|
|
text: l10n?.stop ?? '停止',
|
|
icon: Icons.stop,
|
|
type: ButtonType.danger,
|
|
enabled: false,
|
|
onPressed: null,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
/// 运行状态布局
|
|
Widget _buildRunningState(
|
|
BuildContext context,
|
|
WidgetRef ref,
|
|
AppLocalizations? l10n,
|
|
RunState runState,
|
|
) {
|
|
final runNotifier = ref.read(runStateProvider.notifier);
|
|
|
|
return Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
|
children: [
|
|
// 当前程序名称
|
|
Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
|
|
decoration: BoxDecoration(
|
|
color: AppTheme.cardSelectedBg,
|
|
borderRadius: BorderRadius.circular(6),
|
|
border: Border.all(color: AppTheme.accentPrimary, width: 1),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
Text(
|
|
'${l10n?.selectedProgramLabel ?? '当前选中'}:',
|
|
style: const TextStyle(
|
|
color: AppTheme.textTertiary,
|
|
fontSize: 12,
|
|
),
|
|
),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: Text(
|
|
runState.currentProgram?.name ?? '',
|
|
style: const TextStyle(
|
|
color: AppTheme.accentPrimary,
|
|
fontSize: 14,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
|
|
const SizedBox(height: 12),
|
|
|
|
// 控制按钮
|
|
Row(
|
|
children: [
|
|
// 开始/继续按钮
|
|
Expanded(
|
|
flex: 2,
|
|
child: SizedBox(
|
|
height: 48,
|
|
child: CommonButton(
|
|
text: runState.status == RunStatus.paused
|
|
? (l10n?.continue_ ?? '继续')
|
|
: (l10n?.run ?? '运行'),
|
|
icon: runState.status == RunStatus.paused
|
|
? Icons.play_arrow
|
|
: Icons.play_arrow,
|
|
type: ButtonType.primary,
|
|
onPressed: () => runNotifier.resume(),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: 12),
|
|
// 暂停按钮
|
|
Expanded(
|
|
child: SizedBox(
|
|
height: 48,
|
|
child: CommonButton(
|
|
text: l10n?.pause ?? '暂停',
|
|
icon: Icons.pause,
|
|
type: ButtonType.warning,
|
|
onPressed: runState.status == RunStatus.paused
|
|
? null
|
|
: () => runNotifier.pause(),
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: 12),
|
|
// 停止按钮
|
|
Expanded(
|
|
child: SizedBox(
|
|
height: 48,
|
|
child: CommonButton(
|
|
text: l10n?.stop ?? '停止',
|
|
icon: Icons.stop,
|
|
type: ButtonType.danger,
|
|
onPressed: () => _showStopConfirm(context, runNotifier, l10n),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
|
|
const SizedBox(height: 12),
|
|
|
|
// 状态指示
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Container(
|
|
width: 8,
|
|
height: 8,
|
|
decoration: BoxDecoration(
|
|
shape: BoxShape.circle,
|
|
color: runState.status == RunStatus.paused
|
|
? AppTheme.accentWarning
|
|
: AppTheme.statusRunning,
|
|
),
|
|
),
|
|
const SizedBox(width: 8),
|
|
Text(
|
|
runState.status == RunStatus.paused
|
|
? (l10n?.paused ?? '已暂停')
|
|
: (l10n?.running ?? '运行中'),
|
|
style: TextStyle(
|
|
color: runState.status == RunStatus.paused
|
|
? AppTheme.accentWarning
|
|
: AppTheme.statusRunning,
|
|
fontWeight: FontWeight.w500,
|
|
fontSize: 12,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
/// 显示停止确认对话框
|
|
void _showStopConfirm(
|
|
BuildContext context,
|
|
RunStateNotifier runNotifier,
|
|
AppLocalizations? l10n,
|
|
) {
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) => AlertDialog(
|
|
backgroundColor: AppTheme.cardBg,
|
|
title: Text(
|
|
l10n?.confirm ?? '确认',
|
|
style: const TextStyle(color: AppTheme.textHeading),
|
|
),
|
|
content: Text(
|
|
l10n?.stopConfirm ?? '确定要停止当前运行的程序吗?',
|
|
style: const TextStyle(color: AppTheme.textPrimary),
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
child: Text(
|
|
l10n?.cancel ?? '取消',
|
|
style: const TextStyle(color: AppTheme.textSecondary),
|
|
),
|
|
),
|
|
ElevatedButton(
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: AppTheme.accentCritical,
|
|
foregroundColor: Colors.white,
|
|
),
|
|
onPressed: () {
|
|
runNotifier.stop();
|
|
Navigator.of(context).pop();
|
|
},
|
|
child: Text(l10n?.confirm ?? '确认'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|