重整多余的UI组件和未定功能的逻辑链路的修正
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:maibu_satabot_v2/core/localization/app_localizations.dart';
|
||||
import 'package:maibu_satabot_v2/features/regions/presentation/region_error_text.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import '../../domain/entities/region_draft.dart';
|
||||
import '../cubit/region_editor_cubit.dart';
|
||||
@@ -29,6 +31,8 @@ class RegionFormDialog extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _RegionFormDialogState extends State<RegionFormDialog> {
|
||||
AppLocalizations get _l10n => AppLocalizations.of(context);
|
||||
|
||||
final _form = GlobalKey<FormState>();
|
||||
late final TextEditingController _name;
|
||||
late final TextEditingController _code;
|
||||
@@ -61,7 +65,10 @@ class _RegionFormDialogState extends State<RegionFormDialog> {
|
||||
final state = widget.cubit.state;
|
||||
if (state.isSaving || !_form.currentState!.validate()) return;
|
||||
if (!widget.isScopeCurrent()) {
|
||||
setState(() => _scopeError = '场站或账号已切换,请重新进入编辑器后保存');
|
||||
setState(
|
||||
() =>
|
||||
_scopeError = _l10n.translate('region_editor.scope_changed_reopen'),
|
||||
);
|
||||
return;
|
||||
}
|
||||
setState(() => _scopeError = null);
|
||||
@@ -86,7 +93,10 @@ class _RegionFormDialogState extends State<RegionFormDialog> {
|
||||
Map<int, String> _options(RegionEditorState state) {
|
||||
final result = {for (final route in state.routes) route.id: route.name};
|
||||
for (final id in [..._bound, ?_defaultRoute]) {
|
||||
result.putIfAbsent(id, () => '路线 #$id');
|
||||
result.putIfAbsent(
|
||||
id,
|
||||
() => _l10n.translate('autonomous_work.route_number', {'id': id}),
|
||||
);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -98,7 +108,7 @@ class _RegionFormDialogState extends State<RegionFormDialog> {
|
||||
context: context,
|
||||
builder: (dialogContext) => StatefulBuilder(
|
||||
builder: (_, update) => AlertDialog(
|
||||
title: const Text('绑定路线'),
|
||||
title: Text(_l10n.translate('region_editor.bind_routes')),
|
||||
content: SizedBox(
|
||||
width: 420,
|
||||
height: (MediaQuery.sizeOf(dialogContext).height * 0.5).clamp(
|
||||
@@ -106,7 +116,11 @@ class _RegionFormDialogState extends State<RegionFormDialog> {
|
||||
300.0,
|
||||
),
|
||||
child: options.isEmpty
|
||||
? const Center(child: Text('当前场站暂无可绑定路线'))
|
||||
? Center(
|
||||
child: Text(
|
||||
_l10n.translate('region_editor.no_routes_to_bind'),
|
||||
),
|
||||
)
|
||||
: ListView(
|
||||
children: [
|
||||
for (final route in options.entries)
|
||||
@@ -129,11 +143,11 @@ class _RegionFormDialogState extends State<RegionFormDialog> {
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(dialogContext).pop(),
|
||||
child: const Text('取消'),
|
||||
child: Text(_l10n.translate('common.cancel')),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () => Navigator.of(dialogContext).pop(selected),
|
||||
child: const Text('确定'),
|
||||
child: Text(_l10n.translate('common.ok')),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -181,7 +195,9 @@ class _RegionFormDialogState extends State<RegionFormDialog> {
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
state.draft.id == null ? '新建分区' : '编辑分区',
|
||||
state.draft.id == null
|
||||
? _l10n.translate('region_editor.new_region')
|
||||
: _l10n.translate('region_editor.edit_region'),
|
||||
style: const TextStyle(
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w800,
|
||||
@@ -210,17 +226,25 @@ class _RegionFormDialogState extends State<RegionFormDialog> {
|
||||
TextFormField(
|
||||
key: const ValueKey('region_name'),
|
||||
controller: _name,
|
||||
decoration: _decoration('分区名称 *'),
|
||||
decoration: _decoration(
|
||||
_l10n.translate(
|
||||
'region_editor.region_name_field',
|
||||
),
|
||||
),
|
||||
validator: (value) =>
|
||||
value == null || value.trim().isEmpty
|
||||
? '请填写分区名称'
|
||||
? _l10n.translate(
|
||||
'region_editor.region_name_required',
|
||||
)
|
||||
: null,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
TextFormField(
|
||||
key: const ValueKey('region_code'),
|
||||
controller: _code,
|
||||
decoration: _decoration('分区编码'),
|
||||
decoration: _decoration(
|
||||
_l10n.translate('region_editor.region_code'),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
if (loading) ...[
|
||||
@@ -233,7 +257,14 @@ class _RegionFormDialogState extends State<RegionFormDialog> {
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
state.routesError ?? '路线加载失败',
|
||||
state.routesError == null
|
||||
? _l10n.translate(
|
||||
'region_editor.route_load_failed',
|
||||
)
|
||||
: regionErrorText(
|
||||
state.routesError!,
|
||||
_l10n,
|
||||
),
|
||||
style: const TextStyle(
|
||||
color: Colors.red,
|
||||
fontSize: 12,
|
||||
@@ -242,12 +273,18 @@ class _RegionFormDialogState extends State<RegionFormDialog> {
|
||||
),
|
||||
TextButton(
|
||||
onPressed: widget.cubit.loadRoutes,
|
||||
child: const Text('重新加载路线'),
|
||||
child: Text(
|
||||
_l10n.translate(
|
||||
'region_editor.reload_routes',
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
InputDecorator(
|
||||
decoration: _decoration('默认路线'),
|
||||
decoration: _decoration(
|
||||
_l10n.translate('region_editor.default_route'),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
@@ -261,7 +298,13 @@ class _RegionFormDialogState extends State<RegionFormDialog> {
|
||||
isDense: true,
|
||||
menuMaxHeight: 260,
|
||||
hint: Text(
|
||||
loading ? '路线加载中' : '请选择默认路线(可选)',
|
||||
loading
|
||||
? _l10n.translate(
|
||||
'region_editor.routes_loading',
|
||||
)
|
||||
: _l10n.translate(
|
||||
'region_editor.pick_default_route',
|
||||
),
|
||||
style: const TextStyle(fontSize: 13),
|
||||
),
|
||||
items: [
|
||||
@@ -308,18 +351,22 @@ class _RegionFormDialogState extends State<RegionFormDialog> {
|
||||
? null
|
||||
: () => _pickBoundRoutes(options),
|
||||
child: InputDecorator(
|
||||
decoration: _decoration('绑定路线'),
|
||||
decoration: _decoration(
|
||||
_l10n.translate('region_editor.bind_routes'),
|
||||
),
|
||||
child: Wrap(
|
||||
spacing: 6,
|
||||
runSpacing: 4,
|
||||
children: [
|
||||
if (_bound.isEmpty)
|
||||
const Padding(
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
vertical: 4,
|
||||
),
|
||||
child: Text(
|
||||
'请选择绑定路线(可多选)',
|
||||
_l10n.translate(
|
||||
'region_editor.pick_linked_routes',
|
||||
),
|
||||
style: TextStyle(
|
||||
fontSize: 13,
|
||||
color: Colors.grey,
|
||||
@@ -329,7 +376,11 @@ class _RegionFormDialogState extends State<RegionFormDialog> {
|
||||
for (final id in _bound)
|
||||
InputChip(
|
||||
label: Text(
|
||||
options[id] ?? '路线 #$id',
|
||||
options[id] ??
|
||||
_l10n.translate(
|
||||
'autonomous_work.route_number',
|
||||
{'id': id},
|
||||
),
|
||||
style: const TextStyle(fontSize: 12),
|
||||
),
|
||||
onDeleted: () =>
|
||||
@@ -345,11 +396,15 @@ class _RegionFormDialogState extends State<RegionFormDialog> {
|
||||
controller: _remark,
|
||||
minLines: 2,
|
||||
maxLines: 3,
|
||||
decoration: _decoration('备注'),
|
||||
decoration: _decoration(
|
||||
_l10n.translate('work_v2.record.remark'),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
'当前区域范围点数:${state.draft.scope.length}/4',
|
||||
_l10n.translate('region_editor.boundary_count', {
|
||||
'count': state.draft.scope.length,
|
||||
}),
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: state.draft.scopeError == null
|
||||
@@ -359,7 +414,7 @@ class _RegionFormDialogState extends State<RegionFormDialog> {
|
||||
),
|
||||
if (state.draft.scopeError != null)
|
||||
Text(
|
||||
state.draft.scopeError!,
|
||||
regionErrorText(state.draft.scopeError!, _l10n),
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.red,
|
||||
@@ -369,7 +424,8 @@ class _RegionFormDialogState extends State<RegionFormDialog> {
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 10),
|
||||
child: Text(
|
||||
_scopeError ?? state.error!,
|
||||
_scopeError ??
|
||||
regionErrorText(state.error!, _l10n),
|
||||
key: const ValueKey('region_save_error'),
|
||||
style: const TextStyle(
|
||||
color: Colors.red,
|
||||
@@ -392,7 +448,7 @@ class _RegionFormDialogState extends State<RegionFormDialog> {
|
||||
onPressed: state.isSaving
|
||||
? null
|
||||
: () => Navigator.of(context).pop(false),
|
||||
child: const Text('取消'),
|
||||
child: Text(_l10n.translate('common.cancel')),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
FilledButton(
|
||||
@@ -412,7 +468,9 @@ class _RegionFormDialogState extends State<RegionFormDialog> {
|
||||
color: Colors.white,
|
||||
),
|
||||
)
|
||||
: const Text('确认保存'),
|
||||
: Text(
|
||||
_l10n.translate('region_editor.save_confirm'),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user