feat(dialog): 상세 팝업 SuperportDetailDialog 통합

- SuperportDetailDialog 위젯과 showSuperportDetailDialog 헬퍼를 추가하고 metadata/섹션 패턴을 표준화

- 결재/재고/마스터 각 상세 다이얼로그를 dialogs 디렉터리에 신설하고 기존 페이지를 신규 팝업으로 전환

- SuperportTable 행 선택과 우편번호 검색 다이얼로그 onRowTap 보정을 통해 헤더 오프셋 버그를 제거

- 상세 다이얼로그 및 트랜잭션/상세 뷰 전용 위젯 테스트와 tester_extensions 유틸을 추가하여 회귀를 방지

- detail_dialog_unification_plan.md로 작업 배경과 필드 통합 계획을 문서화
This commit is contained in:
JiWoong Sul
2025-11-07 19:02:43 +09:00
parent 1f78171294
commit 2f8b529506
64 changed files with 13721 additions and 7545 deletions

View File

@@ -1,23 +1,24 @@
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
import 'package:go_router/go_router.dart';
import 'package:intl/intl.dart' as intl;
import 'package:shadcn_ui/shadcn_ui.dart';
import 'package:superport_v2/core/constants/app_sections.dart';
import 'package:superport_v2/widgets/app_layout.dart';
import 'package:superport_v2/widgets/components/filter_bar.dart';
import 'package:superport_v2/widgets/components/superport_dialog.dart';
import 'package:superport_v2/widgets/components/superport_pagination_controls.dart';
import 'package:superport_v2/widgets/components/superport_table.dart';
import 'package:superport_v2/widgets/components/responsive_section.dart';
import 'package:superport_v2/features/util/postal_search/presentation/models/postal_search_result.dart';
import 'package:superport_v2/features/util/postal_search/presentation/widgets/postal_search_dialog.dart';
import '../../../../../core/config/environment.dart';
import '../../../../../widgets/spec_page.dart';
import '../../domain/entities/warehouse.dart';
import '../../domain/repositories/warehouse_repository.dart';
import '../controllers/warehouse_controller.dart';
import '../dialogs/warehouse_detail_dialog.dart';
/// 창고 관리 페이지. 기능 플래그에 따라 사양/실제 화면을 전환한다.
class WarehousePage extends StatelessWidget {
@@ -99,7 +100,7 @@ class _WarehouseEnabledPageState extends State<_WarehouseEnabledPage> {
late final WarehouseController _controller;
final TextEditingController _searchController = TextEditingController();
final FocusNode _searchFocus = FocusNode();
final DateFormat _dateFormat = DateFormat('yyyy-MM-dd HH:mm');
final intl.DateFormat _dateFormat = intl.DateFormat('yyyy-MM-dd HH:mm');
String? _lastError;
String? _lastAppliedRoute;
@@ -178,7 +179,7 @@ class _WarehouseEnabledPageState extends State<_WarehouseEnabledPage> {
leading: const Icon(LucideIcons.plus, size: 16),
onPressed: _controller.isSubmitting
? null
: () => _openWarehouseForm(context),
: _openWarehouseCreateDialog,
child: const Text('신규 등록'),
),
],
@@ -292,14 +293,9 @@ class _WarehouseEnabledPageState extends State<_WarehouseEnabledPage> {
: _WarehouseTable(
warehouses: warehouses,
dateFormat: _dateFormat,
onEdit: _controller.isSubmitting
onWarehouseTap: _controller.isSubmitting
? null
: (warehouse) =>
_openWarehouseForm(context, warehouse: warehouse),
onDelete: _controller.isSubmitting ? null : _confirmDelete,
onRestore: _controller.isSubmitting
? null
: _restoreWarehouse,
: _openWarehouseDetailDialog,
),
),
);
@@ -427,441 +423,51 @@ class _WarehouseEnabledPageState extends State<_WarehouseEnabledPage> {
}
}
Future<void> _openWarehouseForm(
BuildContext context, {
Warehouse? warehouse,
}) async {
final existing = warehouse;
final isEdit = existing != null;
final warehouseId = existing?.id;
if (isEdit && warehouseId == null) {
_showSnack('ID 정보가 없어 수정할 수 없습니다.');
return;
}
final codeController = TextEditingController(
text: existing?.warehouseCode ?? '',
);
final nameController = TextEditingController(
text: existing?.warehouseName ?? '',
);
final zipcodeController = TextEditingController(
text: existing?.zipcode?.zipcode ?? '',
);
final addressController = TextEditingController(
text: existing?.addressDetail ?? '',
);
final noteController = TextEditingController(text: existing?.note ?? '');
final existingZipcode = existing?.zipcode;
final selectedPostalNotifier = ValueNotifier<PostalSearchResult?>(
existingZipcode == null
? null
: PostalSearchResult(
zipcode: existingZipcode.zipcode,
sido: existingZipcode.sido,
sigungu: existingZipcode.sigungu,
roadName: existingZipcode.roadName,
),
);
final isActiveNotifier = ValueNotifier<bool>(existing?.isActive ?? true);
final saving = ValueNotifier<bool>(false);
final codeError = ValueNotifier<String?>(null);
final nameError = ValueNotifier<String?>(null);
final zipcodeError = ValueNotifier<String?>(null);
var isApplyingPostalSelection = false;
void handleZipcodeChange() {
if (isApplyingPostalSelection) {
return;
}
final text = zipcodeController.text.trim();
final selection = selectedPostalNotifier.value;
if (text.isEmpty) {
if (selection != null) {
selectedPostalNotifier.value = null;
}
zipcodeError.value = null;
return;
}
if (selection != null && selection.zipcode != text) {
selectedPostalNotifier.value = null;
}
if (zipcodeError.value != null) {
zipcodeError.value = null;
}
}
void handlePostalSelectionChange() {
if (selectedPostalNotifier.value != null) {
zipcodeError.value = null;
}
}
zipcodeController.addListener(handleZipcodeChange);
selectedPostalNotifier.addListener(handlePostalSelectionChange);
await SuperportDialog.show<bool>(
Future<void> _openWarehouseCreateDialog() async {
final result = await showWarehouseDetailDialog(
context: context,
dialog: SuperportDialog(
title: isEdit ? '창고 수정' : '창고 등록',
description: '창고 기본 정보를 ${isEdit ? '수정' : '입력'}하세요.',
constraints: const BoxConstraints(maxWidth: 540),
primaryAction: ValueListenableBuilder<bool>(
valueListenable: saving,
builder: (context, isSaving, _) {
return ShadButton(
onPressed: isSaving
? null
: () async {
final code = codeController.text.trim();
final name = nameController.text.trim();
final zipcode = zipcodeController.text.trim();
final address = addressController.text.trim();
final note = noteController.text.trim();
final selectedPostal = selectedPostalNotifier.value;
codeError.value = code.isEmpty ? '창고코드를 입력하세요.' : null;
nameError.value = name.isEmpty ? '창고명을 입력하세요.' : null;
zipcodeError.value =
zipcode.isNotEmpty && selectedPostal == null
? '우편번호 검색으로 주소를 선택하세요.'
: null;
if (codeError.value != null ||
nameError.value != null ||
zipcodeError.value != null) {
return;
}
saving.value = true;
final input = WarehouseInput(
warehouseCode: code,
warehouseName: name,
zipcode: zipcode.isEmpty ? null : zipcode,
addressDetail: address.isEmpty ? null : address,
isActive: isActiveNotifier.value,
note: note.isEmpty ? null : note,
);
final navigator = Navigator.of(
context,
rootNavigator: true,
);
final response = isEdit
? await _controller.update(warehouseId!, input)
: await _controller.create(input);
saving.value = false;
if (response != null && mounted) {
if (!navigator.mounted) {
return;
}
_showSnack(isEdit ? '창고를 수정했습니다.' : '창고를 등록했습니다.');
navigator.pop(true);
}
},
child: Text(isEdit ? '저장' : '등록'),
);
},
),
secondaryAction: ValueListenableBuilder<bool>(
valueListenable: saving,
builder: (context, isSaving, _) {
return ShadButton.ghost(
onPressed: isSaving
? null
: () => Navigator.of(context, rootNavigator: true).pop(false),
child: const Text('취소'),
);
},
),
child: Builder(
builder: (dialogContext) {
final theme = ShadTheme.of(dialogContext);
final materialTheme = Theme.of(dialogContext);
Future<void> openPostalSearch() async {
final keyword = zipcodeController.text.trim();
final result = await showPostalSearchDialog(
dialogContext,
initialKeyword: keyword.isEmpty ? null : keyword,
);
if (result == null) {
return;
}
isApplyingPostalSelection = true;
zipcodeController
..text = result.zipcode
..selection = TextSelection.collapsed(
offset: result.zipcode.length,
);
isApplyingPostalSelection = false;
selectedPostalNotifier.value = result;
if (result.fullAddress.isNotEmpty) {
addressController
..text = result.fullAddress
..selection = TextSelection.collapsed(
offset: addressController.text.length,
);
}
}
return SingleChildScrollView(
padding: const EdgeInsets.only(right: 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
ValueListenableBuilder<String?>(
valueListenable: codeError,
builder: (_, errorText, __) {
return _FormField(
label: '창고코드',
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ShadInput(
controller: codeController,
readOnly: isEdit,
onChanged: (_) {
if (codeController.text.trim().isNotEmpty) {
codeError.value = null;
}
},
),
if (errorText != null)
Padding(
padding: const EdgeInsets.only(top: 6),
child: Text(
errorText,
style: theme.textTheme.small.copyWith(
color: materialTheme.colorScheme.error,
),
),
),
],
),
);
},
),
const SizedBox(height: 16),
ValueListenableBuilder<String?>(
valueListenable: nameError,
builder: (_, errorText, __) {
return _FormField(
label: '창고명',
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ShadInput(
controller: nameController,
onChanged: (_) {
if (nameController.text.trim().isNotEmpty) {
nameError.value = null;
}
},
),
if (errorText != null)
Padding(
padding: const EdgeInsets.only(top: 6),
child: Text(
errorText,
style: theme.textTheme.small.copyWith(
color: materialTheme.colorScheme.error,
),
),
),
],
),
);
},
),
const SizedBox(height: 16),
ValueListenableBuilder<String?>(
valueListenable: zipcodeError,
builder: (_, zipcodeErrorText, __) {
return _FormField(
label: '우편번호',
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
Expanded(
child: ShadInput(
controller: zipcodeController,
placeholder: const Text('예: 06000'),
keyboardType: TextInputType.number,
),
),
const SizedBox(width: 8),
ValueListenableBuilder<bool>(
valueListenable: saving,
builder: (_, isSaving, __) {
return ShadButton.outline(
onPressed: isSaving
? null
: openPostalSearch,
child: const Text('검색'),
);
},
),
],
),
const SizedBox(height: 8),
ValueListenableBuilder<PostalSearchResult?>(
valueListenable: selectedPostalNotifier,
builder: (_, selection, __) {
if (selection == null) {
return Text(
'검색 버튼을 눌러 주소를 선택하세요.',
style: theme.textTheme.small.copyWith(
color: theme.colorScheme.mutedForeground,
),
);
}
final fullAddress = selection.fullAddress;
return Text(
fullAddress.isEmpty
? '선택한 우편번호에 주소 정보가 없습니다.'
: fullAddress,
style: theme.textTheme.small,
);
},
),
if (zipcodeErrorText != null)
Padding(
padding: const EdgeInsets.only(top: 6),
child: Text(
zipcodeErrorText,
style: theme.textTheme.small.copyWith(
color: materialTheme.colorScheme.error,
),
),
),
],
),
);
},
),
const SizedBox(height: 16),
_FormField(
label: '상세주소',
child: ShadInput(
controller: addressController,
placeholder: const Text('상세주소 입력'),
),
),
const SizedBox(height: 16),
ValueListenableBuilder<bool>(
valueListenable: isActiveNotifier,
builder: (_, value, __) {
return _FormField(
label: '사용여부',
child: Row(
children: [
ShadSwitch(
value: value,
onChanged: saving.value
? null
: (next) => isActiveNotifier.value = next,
),
const SizedBox(width: 8),
Text(value ? '사용' : '미사용'),
],
),
);
},
),
const SizedBox(height: 16),
_FormField(
label: '비고',
child: ShadTextarea(controller: noteController),
),
if (isEdit) ...[
const SizedBox(height: 20),
Text(
'생성일시: ${_formatDateTime(existing.createdAt)}',
style: theme.textTheme.small,
),
const SizedBox(height: 4),
Text(
'수정일시: ${_formatDateTime(existing.updatedAt)}',
style: theme.textTheme.small,
),
],
],
),
);
},
),
),
dateFormat: _dateFormat,
onCreate: _controller.create,
onUpdate: _controller.update,
onDelete: _controller.delete,
onRestore: _controller.restore,
);
zipcodeController.removeListener(handleZipcodeChange);
selectedPostalNotifier.removeListener(handlePostalSelectionChange);
if (!mounted) {
codeController.dispose();
nameController.dispose();
zipcodeController.dispose();
addressController.dispose();
noteController.dispose();
selectedPostalNotifier.dispose();
isActiveNotifier.dispose();
saving.dispose();
codeError.dispose();
nameError.dispose();
zipcodeError.dispose();
return;
}
codeController.dispose();
nameController.dispose();
zipcodeController.dispose();
addressController.dispose();
noteController.dispose();
selectedPostalNotifier.dispose();
isActiveNotifier.dispose();
saving.dispose();
codeError.dispose();
nameError.dispose();
zipcodeError.dispose();
}
Future<void> _confirmDelete(Warehouse warehouse) async {
final confirmed = await SuperportDialog.show<bool>(
context: context,
dialog: SuperportDialog(
title: '창고 삭제',
description: '"${warehouse.warehouseName}" 창고를 삭제하시겠습니까?',
actions: [
ShadButton.ghost(
onPressed: () =>
Navigator.of(context, rootNavigator: true).pop(false),
child: const Text('취소'),
),
ShadButton(
onPressed: () =>
Navigator.of(context, rootNavigator: true).pop(true),
child: const Text('삭제'),
),
],
),
);
if (confirmed == true && warehouse.id != null) {
final success = await _controller.delete(warehouse.id!);
if (success && mounted) {
_showSnack('창고를 삭제했습니다.');
if (result != null && mounted) {
_showSnack(result.message);
switch (result.action) {
case WarehouseDetailDialogAction.created:
unawaited(_controller.fetch(page: 1));
break;
case WarehouseDetailDialogAction.updated:
case WarehouseDetailDialogAction.deleted:
case WarehouseDetailDialogAction.restored:
unawaited(_controller.fetch(page: _controller.result?.page ?? 1));
break;
}
}
}
Future<void> _restoreWarehouse(Warehouse warehouse) async {
if (warehouse.id == null) return;
final restored = await _controller.restore(warehouse.id!);
if (restored != null && mounted) {
_showSnack('창고를 복구했습니다.');
Future<void> _openWarehouseDetailDialog(Warehouse warehouse) async {
final id = warehouse.id;
if (id == null) {
_showSnack('ID 정보가 없어 상세를 열 수 없습니다.');
return;
}
final result = await showWarehouseDetailDialog(
context: context,
dateFormat: _dateFormat,
warehouse: warehouse,
onCreate: _controller.create,
onUpdate: _controller.update,
onDelete: _controller.delete,
onRestore: _controller.restore,
);
if (result != null && mounted) {
_showSnack(result.message);
unawaited(_controller.fetch(page: _controller.result?.page ?? 1));
}
}
@@ -875,27 +481,18 @@ class _WarehouseEnabledPageState extends State<_WarehouseEnabledPage> {
}
messenger.showSnackBar(SnackBar(content: Text(message)));
}
String _formatDateTime(DateTime? value) {
if (value == null) return '-';
return _dateFormat.format(value.toLocal());
}
}
class _WarehouseTable extends StatelessWidget {
const _WarehouseTable({
required this.warehouses,
required this.dateFormat,
required this.onEdit,
required this.onDelete,
required this.onRestore,
required this.onWarehouseTap,
});
final List<Warehouse> warehouses;
final DateFormat dateFormat;
final void Function(Warehouse warehouse)? onEdit;
final void Function(Warehouse warehouse)? onDelete;
final void Function(Warehouse warehouse)? onRestore;
final intl.DateFormat dateFormat;
final void Function(Warehouse warehouse)? onWarehouseTap;
@override
Widget build(BuildContext context) {
@@ -909,92 +506,47 @@ class _WarehouseTable extends StatelessWidget {
Text('삭제'),
Text('비고'),
Text('변경일시'),
Text('동작'),
];
final rows = warehouses.map((warehouse) {
final cells = <Widget>[
Text(warehouse.id?.toString() ?? '-'),
Text(warehouse.warehouseCode),
Text(warehouse.warehouseName),
Text(warehouse.zipcode?.zipcode ?? '-'),
Text(
warehouse.addressDetail?.isEmpty ?? true
? '-'
: warehouse.addressDetail!,
),
Text(warehouse.isActive ? 'Y' : 'N'),
Text(warehouse.isDeleted ? 'Y' : '-'),
Text(warehouse.note?.isEmpty ?? true ? '-' : warehouse.note!),
Text(
warehouse.updatedAt == null
? '-'
: dateFormat.format(warehouse.updatedAt!.toLocal()),
),
];
cells.add(
ShadTableCell(
alignment: Alignment.centerRight,
child: Wrap(
spacing: 8,
children: [
ShadButton.ghost(
size: ShadButtonSize.sm,
onPressed: onEdit == null ? null : () => onEdit!(warehouse),
child: const Icon(LucideIcons.pencil, size: 16),
),
warehouse.isDeleted
? ShadButton.ghost(
size: ShadButtonSize.sm,
onPressed: onRestore == null
? null
: () => onRestore!(warehouse),
child: const Icon(LucideIcons.history, size: 16),
)
: ShadButton.ghost(
size: ShadButtonSize.sm,
onPressed: onDelete == null
? null
: () => onDelete!(warehouse),
child: const Icon(LucideIcons.trash2, size: 16),
),
],
),
),
);
return cells;
}).toList();
final rows = warehouses
.map(
(warehouse) => <Widget>[
Text(warehouse.id?.toString() ?? '-'),
Text(warehouse.warehouseCode),
Text(warehouse.warehouseName),
Text(warehouse.zipcode?.zipcode ?? '-'),
Text(
warehouse.addressDetail?.isEmpty ?? true
? '-'
: warehouse.addressDetail!,
),
Text(warehouse.isActive ? 'Y' : 'N'),
Text(warehouse.isDeleted ? 'Y' : '-'),
Text(warehouse.note?.isEmpty ?? true ? '-' : warehouse.note!),
Text(
warehouse.updatedAt == null
? '-'
: dateFormat.format(warehouse.updatedAt!.toLocal()),
),
],
)
.toList();
return SuperportTable(
columns: columns,
rows: rows,
rowHeight: 56,
maxHeight: 520,
columnSpanExtent: (index) => index == 9
? const FixedTableSpanExtent(160)
: const FixedTableSpanExtent(140),
);
}
}
class _FormField extends StatelessWidget {
const _FormField({required this.label, required this.child});
final String label;
final Widget child;
@override
Widget build(BuildContext context) {
final theme = ShadTheme.of(context);
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(label, style: theme.textTheme.small),
const SizedBox(height: 6),
child,
],
onRowTap: onWarehouseTap == null
? null
: (index) => onWarehouseTap!(warehouses[index]),
columnSpanExtent: (index) => switch (index) {
1 => const FixedTableSpanExtent(140),
2 => const FixedTableSpanExtent(200),
4 => const FixedTableSpanExtent(220),
8 => const FixedTableSpanExtent(160),
_ => const FixedTableSpanExtent(120),
},
);
}
}