chore(project): 初始化项目基础配置文件

- 添加 CodeGraph、Android 和通用 gitignore 配置
- 创建项目元数据文件跟踪 Flutter 项目属性
- 添加 Codex AI 指导文档 AGENTS.md 说明项目架构
- 配置代码分析选项 analysis_options.yaml
- 设置 Android 应用清单权限和 Kiosk 模式配置
- 实现中英文国际化支持 AppLocalizations
- 配置 GoRouter 应用路由导航
- 创建明亮工业控制风格的主题配置 AppTheme
This commit is contained in:
Developer
2026-06-04 11:19:44 +08:00
commit 5d28bf631b
85 changed files with 21423 additions and 0 deletions

View File

@@ -0,0 +1,199 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import '../../../core/localization/app_localizations.dart';
import '../../../core/theme/app_theme.dart';
import '../../../shared/widgets/common_button.dart';
import '../providers/steps_provider.dart';
import '../widgets/step_list.dart';
import '../widgets/step_form.dart';
import '../../programs/providers/programs_provider.dart';
/// 程序详情页面
/// 左侧步骤列表 + 右侧参数表单
class ProgramDetailPage extends ConsumerStatefulWidget {
final String programId;
const ProgramDetailPage({super.key, required this.programId});
@override
ConsumerState<ProgramDetailPage> createState() => _ProgramDetailPageState();
}
class _ProgramDetailPageState extends ConsumerState<ProgramDetailPage> {
late int _programIdInt;
@override
void initState() {
super.initState();
_programIdInt = int.tryParse(widget.programId) ?? 0;
}
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context);
final programsState = ref.watch(programsProvider);
final program = programsState.programs.where((p) => p.id == _programIdInt).firstOrNull;
final stepsState = ref.watch(stepsProvider(_programIdInt));
return Scaffold(
body: Container(
color: AppTheme.backgroundColor,
child: Column(
children: [
// 顶部导航栏
Container(
height: 60,
padding: const EdgeInsets.symmetric(horizontal: 24),
decoration: BoxDecoration(
color: Colors.white,
boxShadow: [
BoxShadow(
color: Colors.black.withValues(alpha: 0.1),
blurRadius: 4,
offset: const Offset(0, 2),
),
],
),
child: Row(
children: [
// 返回按钮
IconButton(
icon: const Icon(Icons.arrow_back),
onPressed: () => context.go('/programs'),
),
const SizedBox(width: 16),
// 程序名称
Text(
program?.name ?? (l10n?.detail ?? '程序详情'),
style: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.w600,
),
),
const Spacer(),
// 保存按钮
CommonButton(
text: l10n?.save ?? '保存',
icon: Icons.save,
type: ButtonType.primary,
onPressed: () {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('已保存'),
backgroundColor: AppTheme.successColor,
),
);
},
),
],
),
),
// 主内容区域
Expanded(
child: stepsState.isLoading
? const Center(child: CircularProgressIndicator())
: Row(
children: [
// 左侧:步骤列表
SizedBox(
width: 400,
child: StepList(
programId: _programIdInt,
steps: stepsState.steps,
selectedStepId: stepsState.selectedStepId,
onStepSelected: (stepId) {
ref.read(stepsProvider(_programIdInt).notifier).selectStep(stepId);
},
onAddStep: () => _showAddStepDialog(context, ref),
onReorder: (oldIndex, newIndex) {
ref.read(stepsProvider(_programIdInt).notifier).reorderSteps(oldIndex, newIndex);
},
onDeleteSteps: (stepIds) {
ref.read(stepsProvider(_programIdInt).notifier).deleteSteps(stepIds);
},
),
),
// 分隔线
Container(
width: 1,
color: AppTheme.idleColor.withValues(alpha: 0.3),
),
// 右侧:步骤参数表单
Expanded(
child: stepsState.selectedStep != null
? StepForm(
programId: _programIdInt,
step: stepsState.selectedStep!,
onSave: (step) async {
final success = await ref
.read(stepsProvider(_programIdInt).notifier)
.updateStep(step);
if (success) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('步骤已更新'),
backgroundColor: AppTheme.successColor,
),
);
}
},
)
: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.edit_note,
size: 64,
color: AppTheme.idleColor,
),
const SizedBox(height: 16),
Text(
'请选择或添加步骤',
style: TextStyle(
color: AppTheme.textSecondary,
fontSize: 16,
),
),
],
),
),
),
],
),
),
],
),
),
);
}
/// 显示添加步骤对话框
void _showAddStepDialog(BuildContext context, WidgetRef ref) {
showDialog(
context: context,
builder: (context) => Dialog(
child: Container(
width: 600,
padding: const EdgeInsets.all(24),
child: StepForm(
programId: _programIdInt,
isNew: true,
onSave: (step) async {
final success = await ref
.read(stepsProvider(_programIdInt).notifier)
.addStep(step);
if (success) {
Navigator.of(context).pop();
}
},
),
),
),
);
}
}

View File

@@ -0,0 +1,161 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../programs/models/step.dart';
import '../../programs/services/program_service.dart';
/// 步骤状态
class StepsState {
final List<Step> steps;
final int? selectedStepId;
final bool isLoading;
final String? error;
const StepsState({
this.steps = const [],
this.selectedStepId,
this.isLoading = false,
this.error,
});
StepsState copyWith({
List<Step>? steps,
int? selectedStepId,
bool? isLoading,
String? error,
bool clearSelection = false,
bool clearError = false,
}) {
return StepsState(
steps: steps ?? this.steps,
selectedStepId: clearSelection ? null : (selectedStepId ?? this.selectedStepId),
isLoading: isLoading ?? this.isLoading,
error: clearError ? null : (error ?? this.error),
);
}
/// 获取选中的步骤
Step? get selectedStep {
if (selectedStepId == null) return null;
return steps.where((s) => s.id == selectedStepId).firstOrNull;
}
}
/// 步骤 Notifier
class StepsNotifier extends StateNotifier<StepsState> {
final ProgramService _service;
final int programId;
StepsNotifier(this._service, this.programId) : super(const StepsState()) {
loadSteps();
}
/// 加载步骤
Future<void> loadSteps() async {
state = state.copyWith(isLoading: true, clearError: true);
try {
final steps = await _service.getStepsByProgramId(programId);
state = state.copyWith(steps: steps, isLoading: false);
} catch (e) {
state = state.copyWith(isLoading: false, error: e.toString());
}
}
/// 选择步骤
void selectStep(int? stepId) {
state = state.copyWith(selectedStepId: stepId);
}
/// 清除选择
void clearSelection() {
state = state.copyWith(clearSelection: true);
}
/// 添加步骤
Future<bool> addStep(Step step) async {
try {
await _service.addStep(step);
await loadSteps();
return true;
} catch (e) {
state = state.copyWith(error: e.toString());
return false;
}
}
/// 更新步骤
Future<bool> updateStep(Step step) async {
if (step.id == null) return false;
try {
await _service.updateStep(step);
await loadSteps();
return true;
} catch (e) {
state = state.copyWith(error: e.toString());
return false;
}
}
/// 删除步骤
Future<bool> deleteStep(int stepId) async {
try {
await _service.deleteStep(stepId);
if (state.selectedStepId == stepId) {
state = state.copyWith(clearSelection: true);
}
await loadSteps();
return true;
} catch (e) {
state = state.copyWith(error: e.toString());
return false;
}
}
/// 批量删除步骤
Future<bool> deleteSteps(List<int> stepIds) async {
try {
await _service.deleteSteps(stepIds);
if (stepIds.contains(state.selectedStepId)) {
state = state.copyWith(clearSelection: true);
}
await loadSteps();
return true;
} catch (e) {
state = state.copyWith(error: e.toString());
return false;
}
}
/// 重新排序步骤
Future<void> reorderSteps(int oldIndex, int newIndex) async {
final steps = List<Step>.from(state.steps);
final step = steps.removeAt(oldIndex);
steps.insert(newIndex, step);
// 更新 step_no
for (int i = 0; i < steps.length; i++) {
steps[i] = steps[i].copyWith(stepNo: i + 1);
}
state = state.copyWith(steps: steps);
// 持久化排序
await _service.reorderSteps(programId, steps.map((s) => s.id!).toList());
}
}
/// 程序服务 Provider
final programServiceProvider = Provider<ProgramService>((ref) {
return ProgramService.instance;
});
/// 步骤 Provider按程序ID
final stepsProvider = StateNotifierProvider.family<StepsNotifier, StepsState, int>(
(ref, programId) {
final service = ref.watch(programServiceProvider);
return StepsNotifier(service, programId);
},
);
/// 选中的步骤 Provider
final selectedStepProvider = Provider.family<Step?, int>((ref, programId) {
return ref.watch(stepsProvider(programId)).selectedStep;
});

View File

@@ -0,0 +1,270 @@
import 'package:flutter/material.dart';
import '../../../core/localization/app_localizations.dart';
import '../../../core/theme/app_theme.dart';
import '../../../shared/utils/constants.dart';
import '../../../shared/widgets/common_button.dart';
import '../../programs/models/step.dart' as models;
/// 步骤参数表单
class StepForm extends StatefulWidget {
final int programId;
final models.Step? step;
final bool isNew;
final void Function(models.Step) onSave;
const StepForm({
super.key,
required this.programId,
this.step,
this.isNew = false,
required this.onSave,
});
@override
State<StepForm> createState() => _StepFormState();
}
class _StepFormState extends State<StepForm> {
final _formKey = GlobalKey<FormState>();
late TextEditingController _nameController;
late TextEditingController _mixTimeController;
late TextEditingController _magnetTimeController;
late TextEditingController _volumeController;
late TextEditingController _blowTimeController;
String _position = 'A1';
String _mixSpeed = '中速';
String _blowSpeed = '中速';
int _needleSpeed = 5;
@override
void initState() {
super.initState();
_nameController = TextEditingController(text: widget.step?.name ?? '');
_mixTimeController = TextEditingController(text: '${widget.step?.mixTime ?? 0}');
_magnetTimeController = TextEditingController(text: '${widget.step?.magnetTime ?? 0}');
_volumeController = TextEditingController(text: '${widget.step?.volume ?? 0}');
_blowTimeController = TextEditingController(text: '${widget.step?.blowTime ?? 0}');
_position = widget.step?.position ?? 'A1';
_mixSpeed = widget.step?.mixSpeed ?? '中速';
_blowSpeed = widget.step?.blowSpeed ?? '中速';
_needleSpeed = widget.step?.needleSpeed ?? 5;
}
@override
void dispose() {
_nameController.dispose();
_mixTimeController.dispose();
_magnetTimeController.dispose();
_volumeController.dispose();
_blowTimeController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context);
return Padding(
padding: const EdgeInsets.all(24),
child: Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
// 标题
Text(
widget.isNew ? '添加步骤' : '编辑步骤',
style: TextStyle(
color: AppTheme.textPrimary,
fontSize: 18,
fontWeight: FontWeight.w600,
),
),
const SizedBox(height: 24),
// 步骤名称
TextFormField(
controller: _nameController,
decoration: InputDecoration(
labelText: l10n?.stepName ?? '步骤名称',
hintText: '例如: 混合、吸磁、吹气',
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)),
),
validator: (value) {
if (value == null || value.trim().isEmpty) {
return '请输入步骤名称';
}
return null;
},
),
const SizedBox(height: 16),
// 孔位选择
Row(
children: [
Text(l10n?.position ?? '孔位', style: TextStyle(color: AppTheme.textPrimary)),
const SizedBox(width: 16),
Expanded(
child: DropdownButtonFormField<String>(
value: _position,
decoration: InputDecoration(
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)),
),
items: Constants.positions.map((p) => DropdownMenuItem(value: p, child: Text(p))).toList(),
onChanged: (value) {
if (value != null) setState(() => _position = value);
},
),
),
],
),
const SizedBox(height: 16),
// 时间参数行
Row(
children: [
Expanded(
child: TextFormField(
controller: _mixTimeController,
decoration: InputDecoration(
labelText: '${l10n?.mixTime ?? '混合时间'} (${Constants.timeUnitSeconds})',
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)),
),
keyboardType: TextInputType.number,
),
),
const SizedBox(width: 16),
Expanded(
child: TextFormField(
controller: _magnetTimeController,
decoration: InputDecoration(
labelText: '${l10n?.magnetTime ?? '吸磁时间'} (${Constants.timeUnitSeconds})',
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)),
),
keyboardType: TextInputType.number,
),
),
],
),
const SizedBox(height: 16),
// 容积和吹气时间
Row(
children: [
Expanded(
child: TextFormField(
controller: _volumeController,
decoration: InputDecoration(
labelText: '${l10n?.volume ?? '容积'} (${Constants.volumeUnit})',
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)),
),
keyboardType: TextInputType.number,
),
),
const SizedBox(width: 16),
Expanded(
child: TextFormField(
controller: _blowTimeController,
decoration: InputDecoration(
labelText: '${l10n?.blowTime ?? '吹气时间'} (${Constants.timeUnitMinutes})',
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)),
),
keyboardType: TextInputType.number,
),
),
],
),
const SizedBox(height: 16),
// 速度选择
Row(
children: [
Expanded(
child: DropdownButtonFormField<String>(
value: _mixSpeed,
decoration: InputDecoration(
labelText: l10n?.mixSpeed ?? '混合速度',
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)),
),
items: Constants.speedOptions.map((s) => DropdownMenuItem(value: s, child: Text(s))).toList(),
onChanged: (value) {
if (value != null) setState(() => _mixSpeed = value);
},
),
),
const SizedBox(width: 16),
Expanded(
child: DropdownButtonFormField<String>(
value: _blowSpeed,
decoration: InputDecoration(
labelText: l10n?.blowSpeed ?? '吹气速度',
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8)),
),
items: Constants.speedOptions.map((s) => DropdownMenuItem(value: s, child: Text(s))).toList(),
onChanged: (value) {
if (value != null) setState(() => _blowSpeed = value);
},
),
),
],
),
const SizedBox(height: 16),
// 下针速度滑块
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text('${l10n?.needleSpeed ?? '下针速度'}: $_needleSpeed', style: TextStyle(color: AppTheme.textPrimary)),
Slider(
value: _needleSpeed.toDouble(),
min: 1,
max: 10,
divisions: 9,
activeColor: AppTheme.primaryColor,
onChanged: (value) {
setState(() => _needleSpeed = value.round());
},
),
],
),
const SizedBox(height: 24),
// 保存按钮
CommonButton(
text: l10n?.save ?? '保存',
icon: Icons.save,
type: ButtonType.primary,
onPressed: _saveStep,
),
],
),
),
);
}
/// 保存步骤
void _saveStep() {
if (!_formKey.currentState!.validate()) return;
final step = models.Step(
id: widget.step?.id,
programId: widget.programId,
stepNo: widget.step?.stepNo ?? 1,
position: _position,
name: _nameController.text.trim(),
mixTime: int.tryParse(_mixTimeController.text) ?? 0,
magnetTime: int.tryParse(_magnetTimeController.text) ?? 0,
volume: int.tryParse(_volumeController.text) ?? 0,
mixSpeed: _mixSpeed,
blowSpeed: _blowSpeed,
blowTime: int.tryParse(_blowTimeController.text) ?? 0,
needleSpeed: _needleSpeed,
);
widget.onSave(step);
}
}

View File

@@ -0,0 +1,272 @@
import 'package:flutter/material.dart';
import '../../../core/localization/app_localizations.dart';
import '../../../core/theme/app_theme.dart';
import '../../../shared/widgets/common_button.dart';
import '../../programs/models/step.dart' as models;
/// 步骤列表组件
class StepList extends StatefulWidget {
final int programId;
final List<models.Step> steps;
final int? selectedStepId;
final void Function(int?) onStepSelected;
final void Function() onAddStep;
final void Function(int oldIndex, int newIndex)? onReorder;
final void Function(List<int> stepIds)? onDeleteSteps;
const StepList({
super.key,
required this.programId,
required this.steps,
this.selectedStepId,
required this.onStepSelected,
required this.onAddStep,
this.onReorder,
this.onDeleteSteps,
});
@override
State<StepList> createState() => _StepListState();
}
class _StepListState extends State<StepList> {
final Set<int> _selectedIds = {};
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context);
final allSelected = _selectedIds.length == widget.steps.length && widget.steps.isNotEmpty;
return Container(
color: Colors.white,
child: Column(
children: [
// 标题
Container(
height: 50,
padding: const EdgeInsets.symmetric(horizontal: 16),
decoration: BoxDecoration(
color: AppTheme.primaryColor.withValues(alpha: 0.1),
),
child: Row(
children: [
Icon(Icons.list, color: AppTheme.primaryColor, size: 20),
const SizedBox(width: 12),
Text(
'步骤列表',
style: TextStyle(
color: AppTheme.primaryColor,
fontWeight: FontWeight.w600,
),
),
const Spacer(),
Text(
'${widget.steps.length}',
style: TextStyle(
color: AppTheme.textSecondary,
fontSize: 12,
),
),
],
),
),
// 表头
Container(
height: 40,
padding: const EdgeInsets.symmetric(horizontal: 12),
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(color: AppTheme.idleColor.withValues(alpha: 0.2)),
),
),
child: Row(
children: [
SizedBox(
width: 40,
child: Checkbox(
value: allSelected,
onChanged: (value) {
setState(() {
if (value == true) {
_selectedIds.clear();
_selectedIds.addAll(widget.steps.map((s) => s.id!));
} else {
_selectedIds.clear();
}
});
},
),
),
SizedBox(width: 40, child: Text('#', style: TextStyle(fontSize: 12))),
Expanded(child: Text(l10n?.stepName ?? '名称', style: TextStyle(fontSize: 12))),
SizedBox(width: 60, child: Text(l10n?.position ?? '孔位', style: TextStyle(fontSize: 12))),
],
),
),
// 步骤列表(可拖拽排序)
Expanded(
child: widget.steps.isEmpty
? Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.add_circle_outline, size: 48, color: AppTheme.idleColor),
const SizedBox(height: 12),
Text('暂无步骤', style: TextStyle(color: AppTheme.textSecondary)),
],
),
)
: ReorderableListView.builder(
padding: const EdgeInsets.all(8),
itemCount: widget.steps.length,
onReorder: (oldIndex, newIndex) {
if (widget.onReorder != null) {
// 调整 newIndexReorderableListView 的特殊行为)
if (newIndex > oldIndex) newIndex -= 1;
widget.onReorder!(oldIndex, newIndex);
}
},
itemBuilder: (context, index) {
final step = widget.steps[index];
final isSelected = widget.selectedStepId == step.id || _selectedIds.contains(step.id);
return _buildStepItem(step, isSelected, index);
},
),
),
// 底部操作栏
Container(
height: 60,
padding: const EdgeInsets.all(12),
decoration: BoxDecoration(
border: Border(
top: BorderSide(color: AppTheme.idleColor.withValues(alpha: 0.2)),
),
),
child: Row(
children: [
// 添加按钮
CommonButton(
text: '添加',
icon: Icons.add,
type: ButtonType.primary,
onPressed: widget.onAddStep,
),
const SizedBox(width: 12),
// 删除按钮
if (_selectedIds.isNotEmpty)
CommonButton(
text: '删除',
icon: Icons.delete,
type: ButtonType.danger,
onPressed: () => _showDeleteConfirmDialog(context),
),
],
),
),
],
),
);
}
/// 步骤项
Widget _buildStepItem(models.Step step, bool isSelected, int index) {
return Container(
key: ValueKey(step.id),
margin: const EdgeInsets.symmetric(vertical: 2),
decoration: BoxDecoration(
color: isSelected ? AppTheme.primaryLight.withValues(alpha: 0.3) : Colors.white,
borderRadius: BorderRadius.circular(4),
border: isSelected ? Border.all(color: AppTheme.primaryColor, width: 2) : null,
),
child: ListTile(
dense: true,
leading: Checkbox(
value: _selectedIds.contains(step.id),
onChanged: (value) {
setState(() {
if (value == true) {
_selectedIds.add(step.id!);
} else {
_selectedIds.remove(step.id!);
}
});
},
),
title: Row(
children: [
Container(
width: 30,
alignment: Alignment.center,
child: Text(
'${step.stepNo}',
style: TextStyle(
color: AppTheme.primaryColor,
fontWeight: FontWeight.bold,
),
),
),
const SizedBox(width: 8),
Expanded(child: Text(step.name)),
Container(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
decoration: BoxDecoration(
color: AppTheme.primaryColor.withValues(alpha: 0.1),
borderRadius: BorderRadius.circular(4),
),
child: Text(
step.position,
style: TextStyle(
color: AppTheme.primaryColor,
fontSize: 12,
),
),
),
],
),
trailing: Icon(Icons.drag_handle, color: AppTheme.idleColor),
onTap: () => widget.onStepSelected(step.id),
),
);
}
/// 显示删除确认对话框
void _showDeleteConfirmDialog(BuildContext context) {
final l10n = AppLocalizations.of(context);
showDialog(
context: context,
builder: (ctx) => AlertDialog(
title: Text(l10n?.confirm ?? '确认'),
content: Text(
_selectedIds.length == 1
? '确定要删除此步骤吗?'
: '确定要删除选中的 ${_selectedIds.length} 个步骤吗?',
),
actions: [
TextButton(
onPressed: () => Navigator.of(ctx).pop(),
child: Text(l10n?.cancel ?? '取消'),
),
ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: AppTheme.errorColor,
foregroundColor: Colors.white,
),
onPressed: () {
Navigator.of(ctx).pop();
if (widget.onDeleteSteps != null) {
widget.onDeleteSteps!(_selectedIds.toList());
}
setState(() {
_selectedIds.clear();
});
},
child: Text(l10n?.confirm ?? '确认'),
),
],
),
);
}
}