feat(dialog): 상세 팝업 SuperportDetailDialog 통합
- SuperportDetailDialog 위젯과 showSuperportDetailDialog 헬퍼를 추가하고 metadata/섹션 패턴을 표준화 - 결재/재고/마스터 각 상세 다이얼로그를 dialogs 디렉터리에 신설하고 기존 페이지를 신규 팝업으로 전환 - SuperportTable 행 선택과 우편번호 검색 다이얼로그 onRowTap 보정을 통해 헤더 오프셋 버그를 제거 - 상세 다이얼로그 및 트랜잭션/상세 뷰 전용 위젯 테스트와 tester_extensions 유틸을 추가하여 회귀를 방지 - detail_dialog_unification_plan.md로 작업 배경과 필드 통합 계획을 문서화
This commit is contained in:
466
lib/features/masters/vendor/presentation/dialogs/vendor_detail_dialog.dart
vendored
Normal file
466
lib/features/masters/vendor/presentation/dialogs/vendor_detail_dialog.dart
vendored
Normal file
@@ -0,0 +1,466 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:intl/intl.dart' as intl;
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
|
||||
import '../../../../../widgets/components/superport_detail_dialog.dart';
|
||||
import '../../../vendor/domain/entities/vendor.dart';
|
||||
|
||||
/// 벤더 상세 다이얼로그에서 발생한 사용자 액션 종류이다.
|
||||
enum VendorDetailDialogAction { created, updated, deleted, restored }
|
||||
|
||||
/// 벤더 상세 다이얼로그 결과를 담는 모델이다.
|
||||
class VendorDetailDialogResult {
|
||||
const VendorDetailDialogResult({required this.action, required this.message});
|
||||
|
||||
final VendorDetailDialogAction action;
|
||||
final String message;
|
||||
}
|
||||
|
||||
typedef VendorCreateCallback = Future<Vendor?> Function(VendorInput input);
|
||||
typedef VendorUpdateCallback =
|
||||
Future<Vendor?> Function(int id, VendorInput input);
|
||||
typedef VendorDeleteCallback = Future<bool> Function(int id);
|
||||
typedef VendorRestoreCallback = Future<Vendor?> Function(int id);
|
||||
|
||||
/// 벤더 상세 다이얼로그를 표시한다.
|
||||
Future<VendorDetailDialogResult?> showVendorDetailDialog({
|
||||
required BuildContext context,
|
||||
required intl.DateFormat dateFormat,
|
||||
Vendor? vendor,
|
||||
required VendorCreateCallback onCreate,
|
||||
required VendorUpdateCallback onUpdate,
|
||||
required VendorDeleteCallback onDelete,
|
||||
required VendorRestoreCallback onRestore,
|
||||
}) {
|
||||
final metadata = vendor == null
|
||||
? const <SuperportDetailMetadata>[]
|
||||
: [
|
||||
SuperportDetailMetadata.text(
|
||||
label: 'ID',
|
||||
value: vendor.id?.toString() ?? '-',
|
||||
),
|
||||
SuperportDetailMetadata.text(label: '코드', value: vendor.vendorCode),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '상태',
|
||||
value: vendor.isActive ? '사용중' : '미사용',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '삭제 상태',
|
||||
value: vendor.isDeleted ? '삭제됨' : '정상',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '생성일시',
|
||||
value: vendor.createdAt == null
|
||||
? '-'
|
||||
: dateFormat.format(vendor.createdAt!.toLocal()),
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '변경일시',
|
||||
value: vendor.updatedAt == null
|
||||
? '-'
|
||||
: dateFormat.format(vendor.updatedAt!.toLocal()),
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '비고',
|
||||
value: vendor.note?.isEmpty ?? true ? '-' : vendor.note!,
|
||||
),
|
||||
];
|
||||
|
||||
return showSuperportDetailDialog<VendorDetailDialogResult>(
|
||||
context: context,
|
||||
title: vendor == null ? '벤더 등록' : '벤더 상세',
|
||||
description: vendor == null
|
||||
? '새로운 벤더 정보를 입력하세요.'
|
||||
: '벤더 기본 정보와 상태를 확인하고 관리합니다.',
|
||||
sections: [
|
||||
_VendorEditSection(
|
||||
id: vendor == null
|
||||
? _VendorDetailSections.create
|
||||
: _VendorDetailSections.edit,
|
||||
label: vendor == null ? '등록' : '수정',
|
||||
vendor: vendor,
|
||||
onSubmit: (input) async {
|
||||
if (vendor == null) {
|
||||
final created = await onCreate(input);
|
||||
if (created == null) {
|
||||
return null;
|
||||
}
|
||||
return VendorDetailDialogResult(
|
||||
action: VendorDetailDialogAction.created,
|
||||
message: '벤더를 등록했습니다.',
|
||||
);
|
||||
}
|
||||
final updated = await onUpdate(vendor.id!, input);
|
||||
if (updated == null) {
|
||||
return null;
|
||||
}
|
||||
return VendorDetailDialogResult(
|
||||
action: VendorDetailDialogAction.updated,
|
||||
message: '벤더를 수정했습니다.',
|
||||
);
|
||||
},
|
||||
),
|
||||
if (vendor != null)
|
||||
SuperportDetailDialogSection(
|
||||
id: vendor.isDeleted
|
||||
? _VendorDetailSections.restore
|
||||
: _VendorDetailSections.delete,
|
||||
label: vendor.isDeleted ? '복구' : '삭제',
|
||||
icon: vendor.isDeleted ? LucideIcons.history : LucideIcons.trash2,
|
||||
builder: (_) => _VendorDangerSection(
|
||||
vendor: vendor,
|
||||
onDelete: () async {
|
||||
final success = await onDelete(vendor.id!);
|
||||
if (!success) {
|
||||
return null;
|
||||
}
|
||||
return VendorDetailDialogResult(
|
||||
action: VendorDetailDialogAction.deleted,
|
||||
message: '벤더를 삭제했습니다.',
|
||||
);
|
||||
},
|
||||
onRestore: () async {
|
||||
final restored = await onRestore(vendor.id!);
|
||||
if (restored == null) {
|
||||
return null;
|
||||
}
|
||||
return VendorDetailDialogResult(
|
||||
action: VendorDetailDialogAction.restored,
|
||||
message: '벤더를 복구했습니다.',
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
summary: vendor == null
|
||||
? null
|
||||
: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
vendor.vendorName,
|
||||
style: ShadTheme.of(context).textTheme.h4,
|
||||
),
|
||||
],
|
||||
),
|
||||
summaryBadges: vendor == null
|
||||
? const []
|
||||
: [
|
||||
if (vendor.isActive)
|
||||
const ShadBadge(child: Text('사용중'))
|
||||
else
|
||||
const ShadBadge.outline(child: Text('미사용')),
|
||||
if (vendor.isDeleted)
|
||||
const ShadBadge.destructive(child: Text('삭제됨')),
|
||||
],
|
||||
metadata: metadata,
|
||||
emptyPlaceholder: const Text('표시할 상세 정보가 없습니다.'),
|
||||
initialSectionId: vendor == null
|
||||
? _VendorDetailSections.create
|
||||
: _VendorDetailSections.edit,
|
||||
);
|
||||
}
|
||||
|
||||
/// 다이얼로그 섹션 ID 모음.
|
||||
class _VendorDetailSections {
|
||||
static const edit = 'edit';
|
||||
static const delete = 'delete';
|
||||
static const restore = 'restore';
|
||||
static const create = 'create';
|
||||
}
|
||||
|
||||
/// 벤더 등록/수정 폼 섹션이다.
|
||||
class _VendorEditSection extends SuperportDetailDialogSection {
|
||||
_VendorEditSection({
|
||||
required super.id,
|
||||
required super.label,
|
||||
required this.vendor,
|
||||
required this.onSubmit,
|
||||
}) : super(
|
||||
icon: LucideIcons.pencil,
|
||||
builder: (context) => _VendorForm(vendor: vendor, onSubmit: onSubmit),
|
||||
);
|
||||
|
||||
final Vendor? vendor;
|
||||
final Future<VendorDetailDialogResult?> Function(VendorInput input) onSubmit;
|
||||
}
|
||||
|
||||
/// 삭제/복구를 안내하는 위험 섹션이다.
|
||||
class _VendorDangerSection extends StatelessWidget {
|
||||
const _VendorDangerSection({
|
||||
required this.vendor,
|
||||
required this.onDelete,
|
||||
required this.onRestore,
|
||||
});
|
||||
|
||||
final Vendor vendor;
|
||||
final Future<VendorDetailDialogResult?> Function() onDelete;
|
||||
final Future<VendorDetailDialogResult?> Function() onRestore;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
final isDeleted = vendor.isDeleted;
|
||||
final description = isDeleted
|
||||
? '벤더를 복구하면 다시 목록에 노출되고 신규 트랜잭션에서 선택이 가능합니다.'
|
||||
: '삭제하면 벤더가 목록에서 숨겨지고 관련 데이터는 보존됩니다.';
|
||||
final confirmLabel = isDeleted ? '복구' : '삭제';
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(top: 8),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(description, style: theme.textTheme.small),
|
||||
const SizedBox(height: 16),
|
||||
if (isDeleted)
|
||||
ShadButton(
|
||||
onPressed: () async {
|
||||
final navigator = Navigator.of(context, rootNavigator: true);
|
||||
final result = await onRestore();
|
||||
if (result != null && navigator.mounted) {
|
||||
navigator.pop(result);
|
||||
}
|
||||
},
|
||||
child: Text(confirmLabel),
|
||||
)
|
||||
else
|
||||
ShadButton.destructive(
|
||||
onPressed: () async {
|
||||
final navigator = Navigator.of(context, rootNavigator: true);
|
||||
final result = await onDelete();
|
||||
if (result != null && navigator.mounted) {
|
||||
navigator.pop(result);
|
||||
}
|
||||
},
|
||||
child: Text(confirmLabel),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 벤더 입력 폼을 담당하는 위젯이다.
|
||||
class _VendorForm extends StatefulWidget {
|
||||
const _VendorForm({required this.vendor, required this.onSubmit});
|
||||
|
||||
final Vendor? vendor;
|
||||
final Future<VendorDetailDialogResult?> Function(VendorInput input) onSubmit;
|
||||
|
||||
@override
|
||||
State<_VendorForm> createState() => _VendorFormState();
|
||||
}
|
||||
|
||||
class _VendorFormState extends State<_VendorForm> {
|
||||
late final TextEditingController _codeController;
|
||||
late final TextEditingController _nameController;
|
||||
late final TextEditingController _noteController;
|
||||
late final ValueNotifier<bool> _isActiveNotifier;
|
||||
String? _codeError;
|
||||
String? _nameError;
|
||||
String? _submitError;
|
||||
bool _isSubmitting = false;
|
||||
|
||||
bool get _isEdit => widget.vendor != null;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_codeController = TextEditingController(
|
||||
text: widget.vendor?.vendorCode ?? '',
|
||||
);
|
||||
_nameController = TextEditingController(
|
||||
text: widget.vendor?.vendorName ?? '',
|
||||
);
|
||||
_noteController = TextEditingController(text: widget.vendor?.note ?? '');
|
||||
_isActiveNotifier = ValueNotifier<bool>(widget.vendor?.isActive ?? true);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_codeController.dispose();
|
||||
_nameController.dispose();
|
||||
_noteController.dispose();
|
||||
_isActiveNotifier.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_VendorFormField(
|
||||
label: '벤더코드',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ShadInput(
|
||||
controller: _codeController,
|
||||
readOnly: _isEdit,
|
||||
onChanged: (_) {
|
||||
if (_codeController.text.trim().isNotEmpty) {
|
||||
setState(() {
|
||||
_codeError = null;
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
if (_codeError != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
_codeError!,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: theme.colorScheme.destructive,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_VendorFormField(
|
||||
label: '벤더명',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
ShadInput(
|
||||
controller: _nameController,
|
||||
onChanged: (_) {
|
||||
if (_nameController.text.trim().isNotEmpty) {
|
||||
setState(() {
|
||||
_nameError = null;
|
||||
});
|
||||
}
|
||||
},
|
||||
),
|
||||
if (_nameError != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
_nameError!,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: theme.colorScheme.destructive,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_VendorFormField(
|
||||
label: '사용 여부',
|
||||
child: ValueListenableBuilder<bool>(
|
||||
valueListenable: _isActiveNotifier,
|
||||
builder: (_, value, __) {
|
||||
return ShadSwitch(
|
||||
value: value,
|
||||
onChanged: _isSubmitting
|
||||
? null
|
||||
: (next) => _isActiveNotifier.value = next,
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_VendorFormField(
|
||||
label: '비고',
|
||||
child: ShadTextarea(
|
||||
controller: _noteController,
|
||||
minHeight: 96,
|
||||
maxHeight: 200,
|
||||
),
|
||||
),
|
||||
if (_submitError != null) ...[
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
_submitError!,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: theme.colorScheme.destructive,
|
||||
),
|
||||
),
|
||||
],
|
||||
const SizedBox(height: 20),
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: ShadButton(
|
||||
onPressed: _isSubmitting ? null : _handleSubmit,
|
||||
child: Text(_isEdit ? '저장' : '등록'),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _handleSubmit() async {
|
||||
final code = _codeController.text.trim();
|
||||
final name = _nameController.text.trim();
|
||||
|
||||
setState(() {
|
||||
_codeError = code.isEmpty ? '벤더코드를 입력하세요.' : null;
|
||||
_nameError = name.isEmpty ? '벤더명을 입력하세요.' : null;
|
||||
_submitError = null;
|
||||
});
|
||||
|
||||
if (_codeError != null || _nameError != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isSubmitting = true;
|
||||
});
|
||||
|
||||
final input = VendorInput(
|
||||
vendorCode: code,
|
||||
vendorName: name,
|
||||
isActive: _isActiveNotifier.value,
|
||||
note: _noteController.text.trim().isEmpty
|
||||
? null
|
||||
: _noteController.text.trim(),
|
||||
);
|
||||
final navigator = Navigator.of(context, rootNavigator: true);
|
||||
final result = await widget.onSubmit(input);
|
||||
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isSubmitting = false;
|
||||
_submitError = result == null ? '요청 처리에 실패했습니다.' : null;
|
||||
});
|
||||
|
||||
if (result != null && navigator.mounted) {
|
||||
navigator.pop(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// 벤더 폼 필드 레이블/컨텐츠 레이아웃을 제공한다.
|
||||
class _VendorFormField extends StatelessWidget {
|
||||
const _VendorFormField({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,
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 요약 섹션에서 사용할 단순 키-값 모델이다.
|
||||
@@ -1,12 +1,12 @@
|
||||
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';
|
||||
@@ -15,6 +15,7 @@ import '../../../../../core/config/environment.dart';
|
||||
import '../../../../../widgets/spec_page.dart';
|
||||
import '../../../vendor/domain/entities/vendor.dart';
|
||||
import '../../../vendor/domain/repositories/vendor_repository.dart';
|
||||
import '../dialogs/vendor_detail_dialog.dart';
|
||||
import '../controllers/vendor_controller.dart';
|
||||
|
||||
/// 벤더 관리 페이지. 기능 플래그에 따라 사양/실제 화면을 전환한다.
|
||||
@@ -85,7 +86,7 @@ class _VendorEnabledPageState extends State<_VendorEnabledPage> {
|
||||
late final VendorController _controller;
|
||||
final TextEditingController _searchController = TextEditingController();
|
||||
final FocusNode _searchFocusNode = FocusNode();
|
||||
final DateFormat _dateFormat = DateFormat('yyyy-MM-dd HH:mm');
|
||||
final intl.DateFormat _dateFormat = intl.DateFormat('yyyy-MM-dd HH:mm');
|
||||
String? _lastError;
|
||||
String? _lastRouteSignature;
|
||||
|
||||
@@ -165,7 +166,7 @@ class _VendorEnabledPageState extends State<_VendorEnabledPage> {
|
||||
leading: const Icon(LucideIcons.plus, size: 16),
|
||||
onPressed: _controller.isSubmitting
|
||||
? null
|
||||
: () => _openVendorForm(context),
|
||||
: _openVendorCreateDialog,
|
||||
child: const Text('신규 등록'),
|
||||
),
|
||||
],
|
||||
@@ -279,12 +280,10 @@ class _VendorEnabledPageState extends State<_VendorEnabledPage> {
|
||||
)
|
||||
: _VendorTable(
|
||||
vendors: vendors,
|
||||
onEdit: _controller.isSubmitting
|
||||
? null
|
||||
: (vendor) => _openVendorForm(context, vendor: vendor),
|
||||
onDelete: _controller.isSubmitting ? null : _confirmDelete,
|
||||
onRestore: _controller.isSubmitting ? null : _restoreVendor,
|
||||
dateFormat: _dateFormat,
|
||||
onVendorTap: _controller.isSubmitting
|
||||
? null
|
||||
: _openVendorDetailDialog,
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -408,256 +407,37 @@ class _VendorEnabledPageState extends State<_VendorEnabledPage> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _openVendorForm(BuildContext context, {Vendor? vendor}) async {
|
||||
final existingVendor = vendor;
|
||||
final isEdit = existingVendor != null;
|
||||
final vendorId = existingVendor?.id;
|
||||
if (isEdit && vendorId == null) {
|
||||
_showSnack('ID 정보가 없어 수정할 수 없습니다.');
|
||||
Future<void> _openVendorCreateDialog() async {
|
||||
final result = await showVendorDetailDialog(
|
||||
context: context,
|
||||
dateFormat: _dateFormat,
|
||||
onCreate: _controller.create,
|
||||
onUpdate: _controller.update,
|
||||
onDelete: _controller.delete,
|
||||
onRestore: _controller.restore,
|
||||
);
|
||||
if (result != null && mounted) {
|
||||
_showSnack(result.message);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _openVendorDetailDialog(Vendor vendor) async {
|
||||
final vendorId = vendor.id;
|
||||
if (vendorId == null) {
|
||||
_showSnack('ID 정보가 없어 상세를 열 수 없습니다.');
|
||||
return;
|
||||
}
|
||||
|
||||
final codeController = TextEditingController(
|
||||
text: existingVendor?.vendorCode ?? '',
|
||||
);
|
||||
final nameController = TextEditingController(
|
||||
text: existingVendor?.vendorName ?? '',
|
||||
);
|
||||
final noteController = TextEditingController(
|
||||
text: existingVendor?.note ?? '',
|
||||
);
|
||||
final isActiveNotifier = ValueNotifier<bool>(
|
||||
existingVendor?.isActive ?? true,
|
||||
);
|
||||
final saving = ValueNotifier<bool>(false);
|
||||
final codeError = ValueNotifier<String?>(null);
|
||||
final nameError = ValueNotifier<String?>(null);
|
||||
|
||||
await SuperportDialog.show<bool>(
|
||||
final result = await showVendorDetailDialog(
|
||||
context: context,
|
||||
dialog: SuperportDialog(
|
||||
title: isEdit ? '벤더 수정' : '벤더 등록',
|
||||
description: '벤더 기본 정보를 ${isEdit ? '수정' : '입력'}하세요.',
|
||||
constraints: const BoxConstraints(maxWidth: 520),
|
||||
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 note = noteController.text.trim();
|
||||
|
||||
codeError.value = code.isEmpty ? '벤더코드를 입력하세요.' : null;
|
||||
nameError.value = name.isEmpty ? '벤더명을 입력하세요.' : null;
|
||||
|
||||
if (codeError.value != null || nameError.value != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
saving.value = true;
|
||||
final input = VendorInput(
|
||||
vendorCode: code,
|
||||
vendorName: name,
|
||||
isActive: isActiveNotifier.value,
|
||||
note: note.isEmpty ? null : note,
|
||||
);
|
||||
final navigator = Navigator.of(
|
||||
context,
|
||||
rootNavigator: true,
|
||||
);
|
||||
final response = isEdit
|
||||
? await _controller.update(vendorId!, 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);
|
||||
return Padding(
|
||||
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<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(existingVendor.createdAt)}',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'수정일시: ${_formatDateTime(existingVendor.updatedAt)}',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
dateFormat: _dateFormat,
|
||||
vendor: vendor,
|
||||
onCreate: _controller.create,
|
||||
onUpdate: _controller.update,
|
||||
onDelete: _controller.delete,
|
||||
onRestore: _controller.restore,
|
||||
);
|
||||
|
||||
codeController.dispose();
|
||||
nameController.dispose();
|
||||
noteController.dispose();
|
||||
isActiveNotifier.dispose();
|
||||
saving.dispose();
|
||||
codeError.dispose();
|
||||
nameError.dispose();
|
||||
}
|
||||
|
||||
Future<void> _confirmDelete(Vendor vendor) async {
|
||||
final confirmed = await SuperportDialog.show<bool>(
|
||||
context: context,
|
||||
dialog: SuperportDialog(
|
||||
title: '벤더 삭제',
|
||||
description: '"${vendor.vendorName}" 벤더를 삭제하시겠습니까?',
|
||||
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 && vendor.id != null) {
|
||||
final success = await _controller.delete(vendor.id!);
|
||||
if (success && mounted) {
|
||||
_showSnack('벤더를 삭제했습니다.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _restoreVendor(Vendor vendor) async {
|
||||
if (vendor.id == null) return;
|
||||
final restored = await _controller.restore(vendor.id!);
|
||||
if (restored != null && mounted) {
|
||||
_showSnack('벤더를 복구했습니다.');
|
||||
if (result != null && mounted) {
|
||||
_showSnack(result.message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -672,29 +452,18 @@ class _VendorEnabledPageState extends State<_VendorEnabledPage> {
|
||||
}
|
||||
messenger.showSnackBar(SnackBar(content: Text(message)));
|
||||
}
|
||||
|
||||
String _formatDateTime(DateTime? value) {
|
||||
if (value == null) {
|
||||
return '-';
|
||||
}
|
||||
return _dateFormat.format(value.toLocal());
|
||||
}
|
||||
}
|
||||
|
||||
class _VendorTable extends StatelessWidget {
|
||||
const _VendorTable({
|
||||
required this.vendors,
|
||||
required this.onEdit,
|
||||
required this.onDelete,
|
||||
required this.onRestore,
|
||||
required this.dateFormat,
|
||||
required this.onVendorTap,
|
||||
});
|
||||
|
||||
final List<Vendor> vendors;
|
||||
final void Function(Vendor vendor)? onEdit;
|
||||
final void Function(Vendor vendor)? onDelete;
|
||||
final void Function(Vendor vendor)? onRestore;
|
||||
final DateFormat dateFormat;
|
||||
final intl.DateFormat dateFormat;
|
||||
final void Function(Vendor vendor)? onVendorTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -706,86 +475,40 @@ class _VendorTable extends StatelessWidget {
|
||||
Text('삭제'),
|
||||
Text('비고'),
|
||||
Text('변경일시'),
|
||||
Text('동작'),
|
||||
];
|
||||
|
||||
final rows = vendors.map((vendor) {
|
||||
final cells = <Widget>[
|
||||
Text(vendor.id?.toString() ?? '-'),
|
||||
Text(vendor.vendorCode),
|
||||
Text(vendor.vendorName),
|
||||
Text(vendor.isActive ? 'Y' : 'N'),
|
||||
Text(vendor.isDeleted ? 'Y' : '-'),
|
||||
Text(vendor.note?.isEmpty ?? true ? '-' : vendor.note!),
|
||||
Text(
|
||||
vendor.updatedAt == null
|
||||
? '-'
|
||||
: dateFormat.format(vendor.updatedAt!.toLocal()),
|
||||
),
|
||||
];
|
||||
|
||||
cells.add(
|
||||
ShadTableCell(
|
||||
alignment: Alignment.centerRight,
|
||||
child: Wrap(
|
||||
spacing: 8,
|
||||
children: [
|
||||
ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onEdit == null ? null : () => onEdit!(vendor),
|
||||
child: const Icon(LucideIcons.pencil, size: 16),
|
||||
),
|
||||
vendor.isDeleted
|
||||
? ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onRestore == null
|
||||
? null
|
||||
: () => onRestore!(vendor),
|
||||
child: const Icon(LucideIcons.history, size: 16),
|
||||
)
|
||||
: ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onDelete == null
|
||||
? null
|
||||
: () => onDelete!(vendor),
|
||||
child: const Icon(LucideIcons.trash2, size: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return cells;
|
||||
}).toList();
|
||||
final rows = vendors
|
||||
.map(
|
||||
(vendor) => <Widget>[
|
||||
Text(vendor.id?.toString() ?? '-'),
|
||||
Text(vendor.vendorCode),
|
||||
Text(vendor.vendorName),
|
||||
Text(vendor.isActive ? 'Y' : 'N'),
|
||||
Text(vendor.isDeleted ? 'Y' : '-'),
|
||||
Text(vendor.note?.isEmpty ?? true ? '-' : vendor.note!),
|
||||
Text(
|
||||
vendor.updatedAt == null
|
||||
? '-'
|
||||
: dateFormat.format(vendor.updatedAt!.toLocal()),
|
||||
),
|
||||
],
|
||||
)
|
||||
.toList();
|
||||
|
||||
return SuperportTable(
|
||||
columns: columns,
|
||||
rows: rows,
|
||||
rowHeight: 56,
|
||||
maxHeight: 520,
|
||||
columnSpanExtent: (index) => index == 7
|
||||
? 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: onVendorTap == null
|
||||
? null
|
||||
: (index) => onVendorTap!(vendors[index]),
|
||||
columnSpanExtent: (index) => switch (index) {
|
||||
2 => const FixedTableSpanExtent(180),
|
||||
5 => const FixedTableSpanExtent(220),
|
||||
6 => const FixedTableSpanExtent(160),
|
||||
_ => const FixedTableSpanExtent(120),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user