chore(project): 初始化项目基础配置文件
- 添加 CodeGraph、Android 和通用 gitignore 配置 - 创建项目元数据文件跟踪 Flutter 项目属性 - 添加 Codex AI 指导文档 AGENTS.md 说明项目架构 - 配置代码分析选项 analysis_options.yaml - 设置 Android 应用清单权限和 Kiosk 模式配置 - 实现中英文国际化支持 AppLocalizations - 配置 GoRouter 应用路由导航 - 创建明亮工业控制风格的主题配置 AppTheme
This commit is contained in:
270
lib/features/program_detail/widgets/step_form.dart
Normal file
270
lib/features/program_detail/widgets/step_form.dart
Normal 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);
|
||||
}
|
||||
}
|
||||
272
lib/features/program_detail/widgets/step_list.dart
Normal file
272
lib/features/program_detail/widgets/step_list.dart
Normal 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) {
|
||||
// 调整 newIndex(ReorderableListView 的特殊行为)
|
||||
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 ?? '确认'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user