feat(dialog): 상세 팝업 SuperportDetailDialog 통합
- SuperportDetailDialog 위젯과 showSuperportDetailDialog 헬퍼를 추가하고 metadata/섹션 패턴을 표준화 - 결재/재고/마스터 각 상세 다이얼로그를 dialogs 디렉터리에 신설하고 기존 페이지를 신규 팝업으로 전환 - SuperportTable 행 선택과 우편번호 검색 다이얼로그 onRowTap 보정을 통해 헤더 오프셋 버그를 제거 - 상세 다이얼로그 및 트랜잭션/상세 뷰 전용 위젯 테스트와 tester_extensions 유틸을 추가하여 회귀를 방지 - detail_dialog_unification_plan.md로 작업 배경과 필드 통합 계획을 문서화
This commit is contained in:
@@ -0,0 +1,760 @@
|
||||
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 '../../../uom/domain/entities/uom.dart';
|
||||
import '../../../vendor/domain/entities/vendor.dart';
|
||||
import '../../domain/entities/product.dart';
|
||||
import '../widgets/uom_autocomplete_field.dart';
|
||||
import '../widgets/vendor_autocomplete_field.dart';
|
||||
|
||||
/// 제품 상세 다이얼로그에서 발생 가능한 액션 종류이다.
|
||||
enum ProductDetailDialogAction { created, updated, deleted, restored }
|
||||
|
||||
/// 제품 상세 다이얼로그가 반환하는 결과 모델이다.
|
||||
class ProductDetailDialogResult {
|
||||
const ProductDetailDialogResult({
|
||||
required this.action,
|
||||
required this.message,
|
||||
this.product,
|
||||
});
|
||||
|
||||
final ProductDetailDialogAction action;
|
||||
final String message;
|
||||
|
||||
/// 갱신된 제품 엔터티. 삭제 동작의 경우 null일 수 있다.
|
||||
final Product? product;
|
||||
}
|
||||
|
||||
typedef ProductCreateCallback = Future<Product?> Function(ProductInput input);
|
||||
typedef ProductUpdateCallback =
|
||||
Future<Product?> Function(int id, ProductInput input);
|
||||
typedef ProductDeleteCallback = Future<bool> Function(int id);
|
||||
typedef ProductRestoreCallback = Future<Product?> Function(int id);
|
||||
|
||||
/// 제품 상세 다이얼로그를 노출한다.
|
||||
Future<ProductDetailDialogResult?> showProductDetailDialog({
|
||||
required BuildContext context,
|
||||
required intl.DateFormat dateFormat,
|
||||
Product? product,
|
||||
required List<Vendor> vendorOptions,
|
||||
required List<Uom> uomOptions,
|
||||
required ProductCreateCallback onCreate,
|
||||
required ProductUpdateCallback onUpdate,
|
||||
required ProductDeleteCallback onDelete,
|
||||
required ProductRestoreCallback onRestore,
|
||||
}) {
|
||||
final metadata = product == null
|
||||
? const <SuperportDetailMetadata>[]
|
||||
: [
|
||||
SuperportDetailMetadata.text(
|
||||
label: 'ID',
|
||||
value: product.id?.toString() ?? '-',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '제품코드',
|
||||
value: product.productCode,
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '사용 상태',
|
||||
value: product.isActive ? '사용중' : '미사용',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '삭제 여부',
|
||||
value: product.isDeleted ? '삭제됨' : '정상',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '제조사',
|
||||
value: product.vendor == null
|
||||
? '-'
|
||||
: '${product.vendor!.vendorName} (${product.vendor!.vendorCode})',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '단위',
|
||||
value: product.uom?.uomName ?? '-',
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '비고',
|
||||
value: product.note?.isEmpty ?? true ? '-' : product.note!,
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '생성일시',
|
||||
value: product.createdAt == null
|
||||
? '-'
|
||||
: dateFormat.format(product.createdAt!.toLocal()),
|
||||
),
|
||||
SuperportDetailMetadata.text(
|
||||
label: '변경일시',
|
||||
value: product.updatedAt == null
|
||||
? '-'
|
||||
: dateFormat.format(product.updatedAt!.toLocal()),
|
||||
),
|
||||
];
|
||||
|
||||
return showSuperportDetailDialog<ProductDetailDialogResult>(
|
||||
context: context,
|
||||
title: product == null ? '제품 등록' : '제품 상세',
|
||||
description: product == null
|
||||
? '새로운 장비 모델(제품) 정보를 입력하세요.'
|
||||
: '제품 기본 정보와 연결된 제조사·단위 정보를 확인하고 관리합니다.',
|
||||
sections: [
|
||||
if (product != null)
|
||||
SuperportDetailDialogSection(
|
||||
id: _ProductDetailSections.relations,
|
||||
label: '연결 관계',
|
||||
icon: LucideIcons.link,
|
||||
builder: (_) => _ProductRelationsSection(product: product),
|
||||
),
|
||||
if (product != null)
|
||||
SuperportDetailDialogSection(
|
||||
id: _ProductDetailSections.history,
|
||||
label: '히스토리',
|
||||
icon: LucideIcons.clock3,
|
||||
builder: (_) => const _ProductHistorySection(),
|
||||
),
|
||||
_ProductFormSection(
|
||||
id: product == null
|
||||
? _ProductDetailSections.create
|
||||
: _ProductDetailSections.edit,
|
||||
label: product == null ? '등록' : '수정',
|
||||
product: product,
|
||||
vendorOptions: vendorOptions,
|
||||
uomOptions: uomOptions,
|
||||
onSubmit: (input) async {
|
||||
if (product == null) {
|
||||
final created = await onCreate(input);
|
||||
if (created == null) {
|
||||
return null;
|
||||
}
|
||||
return ProductDetailDialogResult(
|
||||
action: ProductDetailDialogAction.created,
|
||||
message: '제품을 등록했습니다.',
|
||||
product: created,
|
||||
);
|
||||
}
|
||||
final updated = await onUpdate(product.id!, input);
|
||||
if (updated == null) {
|
||||
return null;
|
||||
}
|
||||
return ProductDetailDialogResult(
|
||||
action: ProductDetailDialogAction.updated,
|
||||
message: '제품을 수정했습니다.',
|
||||
product: updated,
|
||||
);
|
||||
},
|
||||
),
|
||||
if (product != null)
|
||||
_ProductDangerSection(
|
||||
product: product,
|
||||
onDelete: () async {
|
||||
final id = product.id;
|
||||
if (id == null) {
|
||||
return null;
|
||||
}
|
||||
final success = await onDelete(id);
|
||||
if (!success) {
|
||||
return null;
|
||||
}
|
||||
return ProductDetailDialogResult(
|
||||
action: ProductDetailDialogAction.deleted,
|
||||
message: '제품을 삭제했습니다.',
|
||||
product: product,
|
||||
);
|
||||
},
|
||||
onRestore: () async {
|
||||
final id = product.id;
|
||||
if (id == null) {
|
||||
return null;
|
||||
}
|
||||
final restored = await onRestore(id);
|
||||
if (restored == null) {
|
||||
return null;
|
||||
}
|
||||
return ProductDetailDialogResult(
|
||||
action: ProductDetailDialogAction.restored,
|
||||
message: '제품을 복구했습니다.',
|
||||
product: restored,
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
summary: product == null
|
||||
? null
|
||||
: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
product.productName,
|
||||
style: ShadTheme.of(context).textTheme.h4,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'제품코드 ${product.productCode}',
|
||||
style: ShadTheme.of(context).textTheme.muted,
|
||||
),
|
||||
],
|
||||
),
|
||||
summaryBadges: product == null
|
||||
? const []
|
||||
: [
|
||||
if (product.isActive)
|
||||
const ShadBadge(child: Text('사용중'))
|
||||
else
|
||||
const ShadBadge.outline(child: Text('미사용')),
|
||||
if (product.isDeleted)
|
||||
const ShadBadge.destructive(child: Text('삭제됨')),
|
||||
],
|
||||
metadata: metadata,
|
||||
initialSectionId: product == null
|
||||
? _ProductDetailSections.create
|
||||
: _ProductDetailSections.relations,
|
||||
emptyPlaceholder: const Text('표시할 세부 정보가 없습니다.'),
|
||||
);
|
||||
}
|
||||
|
||||
/// 제품 상세 다이얼로그 섹션 정의 모음이다.
|
||||
class _ProductDetailSections {
|
||||
static const relations = 'relations';
|
||||
static const history = 'history';
|
||||
static const edit = 'edit';
|
||||
static const delete = 'delete';
|
||||
static const restore = 'restore';
|
||||
static const create = 'create';
|
||||
}
|
||||
|
||||
/// 제품과 연결된 제조사/단위 정보를 표시하는 섹션이다.
|
||||
class _ProductRelationsSection extends StatelessWidget {
|
||||
const _ProductRelationsSection({required this.product});
|
||||
|
||||
final Product product;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
final vendor = product.vendor;
|
||||
final uom = product.uom;
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_RelationTile(
|
||||
icon: LucideIcons.factory,
|
||||
title: '제조사',
|
||||
description: vendor == null
|
||||
? '연결된 제조사가 없습니다.'
|
||||
: '${vendor.vendorName} (${vendor.vendorCode})',
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_RelationTile(
|
||||
icon: LucideIcons.scale,
|
||||
title: '단위(UOM)',
|
||||
description: uom == null ? '연결된 단위 정보가 없습니다.' : uom.uomName,
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'하단의 수정 섹션에서 제조사와 단위를 변경할 수 있습니다.',
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: theme.colorScheme.mutedForeground,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 제품 변경 이력을 안내하는 섹션이다.
|
||||
class _ProductHistorySection extends StatelessWidget {
|
||||
const _ProductHistorySection();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('현재 제품 변경 이력 데이터는 준비 중입니다.', style: theme.textTheme.small),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
'재고 입출고 추적 기능이 추가되면 히스토리를 통해 상태 변화를 확인할 수 있습니다.',
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: theme.colorScheme.mutedForeground,
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 제품 등록/수정 폼을 제공하는 섹션이다.
|
||||
class _ProductFormSection extends SuperportDetailDialogSection {
|
||||
_ProductFormSection({
|
||||
required super.id,
|
||||
required super.label,
|
||||
required Product? product,
|
||||
required this.vendorOptions,
|
||||
required this.uomOptions,
|
||||
required this.onSubmit,
|
||||
}) : super(
|
||||
icon: LucideIcons.pencil,
|
||||
builder: (context) => _ProductForm(
|
||||
product: product,
|
||||
vendorOptions: vendorOptions,
|
||||
uomOptions: uomOptions,
|
||||
onSubmit: onSubmit,
|
||||
),
|
||||
);
|
||||
|
||||
final List<Vendor> vendorOptions;
|
||||
final List<Uom> uomOptions;
|
||||
final Future<ProductDetailDialogResult?> Function(ProductInput input)
|
||||
onSubmit;
|
||||
}
|
||||
|
||||
/// 제품 삭제/복구 액션을 제공하는 섹션이다.
|
||||
class _ProductDangerSection extends SuperportDetailDialogSection {
|
||||
_ProductDangerSection({
|
||||
required this.product,
|
||||
required this.onDelete,
|
||||
required this.onRestore,
|
||||
}) : super(
|
||||
id: product.isDeleted
|
||||
? _ProductDetailSections.restore
|
||||
: _ProductDetailSections.delete,
|
||||
label: product.isDeleted ? '복구' : '삭제',
|
||||
icon: product.isDeleted ? LucideIcons.history : LucideIcons.trash2,
|
||||
builder: (context) => _ProductDangerContent(
|
||||
product: product,
|
||||
onDelete: onDelete,
|
||||
onRestore: onRestore,
|
||||
),
|
||||
scrollable: false,
|
||||
);
|
||||
|
||||
final Product product;
|
||||
final Future<ProductDetailDialogResult?> Function() onDelete;
|
||||
final Future<ProductDetailDialogResult?> Function() onRestore;
|
||||
}
|
||||
|
||||
/// 제품 삭제/복구 안내 레이아웃이다.
|
||||
class _ProductDangerContent extends StatelessWidget {
|
||||
const _ProductDangerContent({
|
||||
required this.product,
|
||||
required this.onDelete,
|
||||
required this.onRestore,
|
||||
});
|
||||
|
||||
final Product product;
|
||||
final Future<ProductDetailDialogResult?> Function() onDelete;
|
||||
final Future<ProductDetailDialogResult?> Function() onRestore;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
final isDeleted = product.isDeleted;
|
||||
final description = isDeleted
|
||||
? '제품을 복구하면 다시 목록에 노출되고 재고 등록 시 선택할 수 있습니다.'
|
||||
: '삭제하면 제품이 목록에서 숨겨지며 기존 데이터는 유지됩니다.';
|
||||
final confirmLabel = isDeleted ? '복구' : '삭제';
|
||||
|
||||
return 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 _ProductForm extends StatefulWidget {
|
||||
const _ProductForm({
|
||||
required this.product,
|
||||
required this.vendorOptions,
|
||||
required this.uomOptions,
|
||||
required this.onSubmit,
|
||||
});
|
||||
|
||||
final Product? product;
|
||||
final List<Vendor> vendorOptions;
|
||||
final List<Uom> uomOptions;
|
||||
final Future<ProductDetailDialogResult?> Function(ProductInput input)
|
||||
onSubmit;
|
||||
|
||||
@override
|
||||
State<_ProductForm> createState() => _ProductFormState();
|
||||
}
|
||||
|
||||
class _ProductFormState extends State<_ProductForm> {
|
||||
late final TextEditingController _codeController;
|
||||
late final TextEditingController _nameController;
|
||||
late final TextEditingController _noteController;
|
||||
late final ValueNotifier<int?> _vendorNotifier;
|
||||
late final ValueNotifier<int?> _uomNotifier;
|
||||
late final ValueNotifier<bool> _isActiveNotifier;
|
||||
String? _codeError;
|
||||
String? _nameError;
|
||||
String? _vendorError;
|
||||
String? _uomError;
|
||||
String? _submitError;
|
||||
bool _isSubmitting = false;
|
||||
|
||||
bool get _isEdit => widget.product != null;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
final product = widget.product;
|
||||
_codeController = TextEditingController(text: product?.productCode ?? '');
|
||||
_nameController = TextEditingController(text: product?.productName ?? '');
|
||||
_noteController = TextEditingController(text: product?.note ?? '');
|
||||
_vendorNotifier = ValueNotifier<int?>(product?.vendor?.id);
|
||||
_uomNotifier = ValueNotifier<int?>(product?.uom?.id);
|
||||
_isActiveNotifier = ValueNotifier<bool>(product?.isActive ?? true);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_codeController.dispose();
|
||||
_nameController.dispose();
|
||||
_noteController.dispose();
|
||||
_vendorNotifier.dispose();
|
||||
_uomNotifier.dispose();
|
||||
_isActiveNotifier.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_ProductFormField(
|
||||
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),
|
||||
_ProductFormField(
|
||||
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),
|
||||
_ProductFormField(
|
||||
label: '제조사',
|
||||
child: ValueListenableBuilder<int?>(
|
||||
valueListenable: _vendorNotifier,
|
||||
builder: (_, vendorId, __) {
|
||||
final initialLabel = widget.product?.vendor == null
|
||||
? null
|
||||
: '${widget.product!.vendor!.vendorName} '
|
||||
'(${widget.product!.vendor!.vendorCode})';
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
VendorAutocompleteField(
|
||||
initialOptions: widget.vendorOptions,
|
||||
selectedVendorId: vendorId,
|
||||
initialLabel: initialLabel,
|
||||
onSelected: (id) {
|
||||
_vendorNotifier.value = id;
|
||||
setState(() {
|
||||
_vendorError = null;
|
||||
});
|
||||
},
|
||||
),
|
||||
if (_vendorError != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
_vendorError!,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: theme.colorScheme.destructive,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_ProductFormField(
|
||||
label: '단위',
|
||||
child: ValueListenableBuilder<int?>(
|
||||
valueListenable: _uomNotifier,
|
||||
builder: (_, uomId, __) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
UomAutocompleteField(
|
||||
initialOptions: widget.uomOptions,
|
||||
selectedUomId: uomId,
|
||||
initialLabel: widget.product?.uom?.uomName,
|
||||
onSelected: (id) {
|
||||
_uomNotifier.value = id;
|
||||
setState(() {
|
||||
_uomError = null;
|
||||
});
|
||||
},
|
||||
),
|
||||
if (_uomError != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
_uomError!,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
color: theme.colorScheme.destructive,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_ProductFormField(
|
||||
label: '사용여부',
|
||||
child: ValueListenableBuilder<bool>(
|
||||
valueListenable: _isActiveNotifier,
|
||||
builder: (_, value, __) {
|
||||
return Row(
|
||||
children: [
|
||||
ShadSwitch(
|
||||
value: value,
|
||||
onChanged: _isSubmitting
|
||||
? null
|
||||
: (next) => _isActiveNotifier.value = next,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(value ? '사용' : '미사용'),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
_ProductFormField(
|
||||
label: '비고',
|
||||
child: ShadTextarea(
|
||||
controller: _noteController,
|
||||
minHeight: 96,
|
||||
maxHeight: 240,
|
||||
),
|
||||
),
|
||||
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();
|
||||
final vendorId = _vendorNotifier.value;
|
||||
final uomId = _uomNotifier.value;
|
||||
|
||||
setState(() {
|
||||
_codeError = code.isEmpty ? '제품코드를 입력하세요.' : null;
|
||||
_nameError = name.isEmpty ? '제품명을 입력하세요.' : null;
|
||||
_vendorError = vendorId == null ? '제조사를 선택하세요.' : null;
|
||||
_uomError = uomId == null ? '단위를 선택하세요.' : null;
|
||||
_submitError = null;
|
||||
});
|
||||
|
||||
if (_codeError != null ||
|
||||
_nameError != null ||
|
||||
_vendorError != null ||
|
||||
_uomError != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isSubmitting = true;
|
||||
});
|
||||
|
||||
final input = ProductInput(
|
||||
productCode: code,
|
||||
productName: name,
|
||||
vendorId: vendorId!,
|
||||
uomId: uomId!,
|
||||
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 _ProductFormField extends StatelessWidget {
|
||||
const _ProductFormField({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,
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 관계 타일을 렌더링하는 위젯이다.
|
||||
class _RelationTile extends StatelessWidget {
|
||||
const _RelationTile({
|
||||
required this.icon,
|
||||
required this.title,
|
||||
required this.description,
|
||||
});
|
||||
|
||||
final IconData icon;
|
||||
final String title;
|
||||
final String description;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = ShadTheme.of(context);
|
||||
return ShadCard(
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 12, top: 4),
|
||||
child: Icon(icon, size: 18),
|
||||
),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: theme.textTheme.small.copyWith(
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(description, style: theme.textTheme.small),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 키-값 행 데이터를 표현하는 모델이다.
|
||||
@@ -1,12 +1,14 @@
|
||||
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';
|
||||
@@ -20,8 +22,7 @@ import '../../../vendor/domain/repositories/vendor_repository.dart';
|
||||
import '../../domain/entities/product.dart';
|
||||
import '../../domain/repositories/product_repository.dart';
|
||||
import '../controllers/product_controller.dart';
|
||||
import '../widgets/uom_autocomplete_field.dart';
|
||||
import '../widgets/vendor_autocomplete_field.dart';
|
||||
import '../dialogs/product_detail_dialog.dart';
|
||||
|
||||
/// 제품 관리 페이지. 기능 플래그에 따라 사양/실제 화면을 전환한다.
|
||||
class ProductPage extends StatelessWidget {
|
||||
@@ -94,7 +95,7 @@ class _ProductEnabledPageState extends State<_ProductEnabledPage> {
|
||||
late final ProductController _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');
|
||||
bool _lookupsLoaded = false;
|
||||
String? _lastError;
|
||||
String? _lastRouteSignature;
|
||||
@@ -178,7 +179,7 @@ class _ProductEnabledPageState extends State<_ProductEnabledPage> {
|
||||
leading: const Icon(LucideIcons.plus, size: 16),
|
||||
onPressed: _controller.isSubmitting
|
||||
? null
|
||||
: () => _openProductForm(context),
|
||||
: _openProductCreateDialog,
|
||||
child: const Text('신규 등록'),
|
||||
),
|
||||
],
|
||||
@@ -348,14 +349,9 @@ class _ProductEnabledPageState extends State<_ProductEnabledPage> {
|
||||
: _ProductTable(
|
||||
products: products,
|
||||
dateFormat: _dateFormat,
|
||||
onEdit: _controller.isSubmitting
|
||||
onProductTap: _controller.isSubmitting
|
||||
? null
|
||||
: (product) =>
|
||||
_openProductForm(context, product: product),
|
||||
onDelete: _controller.isSubmitting ? null : _confirmDelete,
|
||||
onRestore: _controller.isSubmitting
|
||||
? null
|
||||
: _restoreProduct,
|
||||
: _openProductDetailDialog,
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -510,369 +506,61 @@ class _ProductEnabledPageState extends State<_ProductEnabledPage> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _openProductForm(
|
||||
BuildContext context, {
|
||||
Product? product,
|
||||
}) async {
|
||||
final existing = product;
|
||||
final isEdit = existing != null;
|
||||
final productId = existing?.id;
|
||||
if (isEdit && productId == null) {
|
||||
_showSnack('ID 정보가 없어 수정할 수 없습니다.');
|
||||
return;
|
||||
}
|
||||
|
||||
Future<void> _openProductCreateDialog() async {
|
||||
if (!_lookupsLoaded) {
|
||||
_showSnack('선택 목록을 불러오는 중입니다. 잠시 후 다시 시도하세요.');
|
||||
return;
|
||||
}
|
||||
|
||||
final parentContext = context;
|
||||
|
||||
final codeController = TextEditingController(
|
||||
text: existing?.productCode ?? '',
|
||||
);
|
||||
final nameController = TextEditingController(
|
||||
text: existing?.productName ?? '',
|
||||
);
|
||||
final noteController = TextEditingController(text: existing?.note ?? '');
|
||||
final vendorNotifier = ValueNotifier<int?>(existing?.vendor?.id);
|
||||
final uomNotifier = ValueNotifier<int?>(existing?.uom?.id);
|
||||
final isActiveNotifier = ValueNotifier<bool>(existing?.isActive ?? true);
|
||||
final saving = ValueNotifier<bool>(false);
|
||||
final codeError = ValueNotifier<String?>(null);
|
||||
final nameError = ValueNotifier<String?>(null);
|
||||
final vendorError = ValueNotifier<String?>(null);
|
||||
final uomError = ValueNotifier<String?>(null);
|
||||
|
||||
await SuperportDialog.show<bool>(
|
||||
context: parentContext,
|
||||
dialog: SuperportDialog(
|
||||
title: isEdit ? '제품 수정' : '제품 등록',
|
||||
description: '제품 기본 정보를 ${isEdit ? '수정' : '입력'}하세요.',
|
||||
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();
|
||||
final vendorId = vendorNotifier.value;
|
||||
final uomId = uomNotifier.value;
|
||||
|
||||
codeError.value = code.isEmpty ? '제품코드를 입력하세요.' : null;
|
||||
nameError.value = name.isEmpty ? '제품명을 입력하세요.' : null;
|
||||
vendorError.value = vendorId == null
|
||||
? '제조사를 선택하세요.'
|
||||
: null;
|
||||
uomError.value = uomId == null ? '단위를 선택하세요.' : null;
|
||||
|
||||
if (codeError.value != null ||
|
||||
nameError.value != null ||
|
||||
vendorError.value != null ||
|
||||
uomError.value != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
saving.value = true;
|
||||
final input = ProductInput(
|
||||
productCode: code,
|
||||
productName: name,
|
||||
vendorId: vendorId!,
|
||||
uomId: uomId!,
|
||||
isActive: isActiveNotifier.value,
|
||||
note: note.isEmpty ? null : note,
|
||||
);
|
||||
final navigator = Navigator.of(
|
||||
context,
|
||||
rootNavigator: true,
|
||||
);
|
||||
final response = isEdit
|
||||
? await _controller.update(productId!, 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: ValueListenableBuilder<bool>(
|
||||
valueListenable: saving,
|
||||
builder: (context, isSaving, _) {
|
||||
final theme = ShadTheme.of(context);
|
||||
final materialTheme = Theme.of(context);
|
||||
return SingleChildScrollView(
|
||||
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<int?>(
|
||||
valueListenable: vendorNotifier,
|
||||
builder: (_, value, __) {
|
||||
return ValueListenableBuilder<String?>(
|
||||
valueListenable: vendorError,
|
||||
builder: (_, errorText, __) {
|
||||
final vendorLabel = () {
|
||||
final vendor = existing?.vendor;
|
||||
if (vendor == null) {
|
||||
return null;
|
||||
}
|
||||
return '${vendor.vendorName} (${vendor.vendorCode})';
|
||||
}();
|
||||
return _FormField(
|
||||
label: '제조사',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
VendorAutocompleteField(
|
||||
initialOptions: _controller.vendorOptions,
|
||||
selectedVendorId: value,
|
||||
initialLabel: vendorLabel,
|
||||
enabled: !isSaving,
|
||||
placeholder: const Text('제조사를 선택하세요'),
|
||||
onSelected: (id) {
|
||||
debugPrint(
|
||||
'[ProductForm] 제조사 선택 -> id=$id',
|
||||
);
|
||||
vendorNotifier.value = id;
|
||||
vendorError.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<int?>(
|
||||
valueListenable: uomNotifier,
|
||||
builder: (_, value, __) {
|
||||
return ValueListenableBuilder<String?>(
|
||||
valueListenable: uomError,
|
||||
builder: (_, errorText, __) {
|
||||
final uomLabel = existing?.uom?.uomName;
|
||||
return _FormField(
|
||||
label: '단위',
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
UomAutocompleteField(
|
||||
initialOptions: _controller.uomOptions,
|
||||
selectedUomId: value,
|
||||
initialLabel: uomLabel,
|
||||
enabled: !isSaving,
|
||||
placeholder: const Text('단위를 선택하세요'),
|
||||
onSelected: (id) {
|
||||
debugPrint('[ProductForm] 단위 선택 -> id=$id');
|
||||
uomNotifier.value = id;
|
||||
uomError.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(existing.createdAt)}',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'수정일시: ${_formatDateTime(existing.updatedAt)}',
|
||||
style: theme.textTheme.small,
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
codeController.dispose();
|
||||
nameController.dispose();
|
||||
noteController.dispose();
|
||||
vendorNotifier.dispose();
|
||||
uomNotifier.dispose();
|
||||
isActiveNotifier.dispose();
|
||||
saving.dispose();
|
||||
codeError.dispose();
|
||||
nameError.dispose();
|
||||
vendorError.dispose();
|
||||
uomError.dispose();
|
||||
}
|
||||
|
||||
Future<void> _confirmDelete(Product product) async {
|
||||
final bool? confirmed = await SuperportDialog.show<bool>(
|
||||
final result = await showProductDetailDialog(
|
||||
context: context,
|
||||
dialog: SuperportDialog(
|
||||
title: '제품 삭제',
|
||||
description: '"${product.productName}" 제품을 삭제하시겠습니까?',
|
||||
primaryAction: ShadButton.destructive(
|
||||
onPressed: () => Navigator.of(context, rootNavigator: true).pop(true),
|
||||
child: const Text('삭제'),
|
||||
),
|
||||
secondaryAction: ShadButton.ghost(
|
||||
onPressed: () =>
|
||||
Navigator.of(context, rootNavigator: true).pop(false),
|
||||
child: const Text('취소'),
|
||||
),
|
||||
),
|
||||
dateFormat: _dateFormat,
|
||||
vendorOptions: _controller.vendorOptions,
|
||||
uomOptions: _controller.uomOptions,
|
||||
onCreate: _controller.create,
|
||||
onUpdate: _controller.update,
|
||||
onDelete: _controller.delete,
|
||||
onRestore: _controller.restore,
|
||||
);
|
||||
|
||||
if (confirmed == true && product.id != null) {
|
||||
final success = await _controller.delete(product.id!);
|
||||
if (success && mounted) {
|
||||
_showSnack('제품을 삭제했습니다.');
|
||||
if (result != null && mounted) {
|
||||
_showSnack(result.message);
|
||||
switch (result.action) {
|
||||
case ProductDetailDialogAction.created:
|
||||
unawaited(_controller.fetch(page: 1));
|
||||
break;
|
||||
case ProductDetailDialogAction.updated:
|
||||
case ProductDetailDialogAction.deleted:
|
||||
case ProductDetailDialogAction.restored:
|
||||
final currentPage = _controller.result?.page ?? 1;
|
||||
unawaited(_controller.fetch(page: currentPage));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _restoreProduct(Product product) async {
|
||||
if (product.id == null) return;
|
||||
final restored = await _controller.restore(product.id!);
|
||||
if (restored != null && mounted) {
|
||||
_showSnack('제품을 복구했습니다.');
|
||||
Future<void> _openProductDetailDialog(Product product) async {
|
||||
final productId = product.id;
|
||||
if (productId == null) {
|
||||
_showSnack('ID 정보가 없어 상세를 열 수 없습니다.');
|
||||
return;
|
||||
}
|
||||
|
||||
final result = await showProductDetailDialog(
|
||||
context: context,
|
||||
dateFormat: _dateFormat,
|
||||
product: product,
|
||||
vendorOptions: _controller.vendorOptions,
|
||||
uomOptions: _controller.uomOptions,
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -886,27 +574,18 @@ class _ProductEnabledPageState extends State<_ProductEnabledPage> {
|
||||
}
|
||||
messenger.showSnackBar(SnackBar(content: Text(message)));
|
||||
}
|
||||
|
||||
String _formatDateTime(DateTime? value) {
|
||||
if (value == null) return '-';
|
||||
return _dateFormat.format(value.toLocal());
|
||||
}
|
||||
}
|
||||
|
||||
class _ProductTable extends StatelessWidget {
|
||||
const _ProductTable({
|
||||
required this.products,
|
||||
required this.dateFormat,
|
||||
required this.onEdit,
|
||||
required this.onDelete,
|
||||
required this.onRestore,
|
||||
required this.onProductTap,
|
||||
});
|
||||
|
||||
final List<Product> products;
|
||||
final DateFormat dateFormat;
|
||||
final void Function(Product product)? onEdit;
|
||||
final void Function(Product product)? onDelete;
|
||||
final void Function(Product product)? onRestore;
|
||||
final intl.DateFormat dateFormat;
|
||||
final void Function(Product product)? onProductTap;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@@ -920,88 +599,41 @@ class _ProductTable extends StatelessWidget {
|
||||
Text('삭제'),
|
||||
Text('비고'),
|
||||
Text('변경일시'),
|
||||
Text('동작'),
|
||||
];
|
||||
|
||||
final rows = products.map((product) {
|
||||
final cells = <Widget>[
|
||||
Text(product.id?.toString() ?? '-'),
|
||||
Text(product.productCode),
|
||||
Text(product.productName),
|
||||
Text(product.vendor?.vendorName ?? '-'),
|
||||
Text(product.uom?.uomName ?? '-'),
|
||||
Text(product.isActive ? 'Y' : 'N'),
|
||||
Text(product.isDeleted ? 'Y' : '-'),
|
||||
Text(product.note?.isEmpty ?? true ? '-' : product.note!),
|
||||
Text(
|
||||
product.updatedAt == null
|
||||
? '-'
|
||||
: dateFormat.format(product.updatedAt!.toLocal()),
|
||||
),
|
||||
];
|
||||
|
||||
cells.add(
|
||||
ShadTableCell(
|
||||
alignment: Alignment.centerRight,
|
||||
child: Wrap(
|
||||
spacing: 8,
|
||||
children: [
|
||||
ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onEdit == null ? null : () => onEdit!(product),
|
||||
child: const Icon(LucideIcons.pencil, size: 16),
|
||||
),
|
||||
product.isDeleted
|
||||
? ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onRestore == null
|
||||
? null
|
||||
: () => onRestore!(product),
|
||||
child: const Icon(LucideIcons.history, size: 16),
|
||||
)
|
||||
: ShadButton.ghost(
|
||||
size: ShadButtonSize.sm,
|
||||
onPressed: onDelete == null
|
||||
? null
|
||||
: () => onDelete!(product),
|
||||
child: const Icon(LucideIcons.trash2, size: 16),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return cells;
|
||||
}).toList();
|
||||
|
||||
return SuperportTable(
|
||||
columns: columns,
|
||||
rows: rows,
|
||||
rows: products
|
||||
.map(
|
||||
(product) => <Widget>[
|
||||
Text(product.id?.toString() ?? '-'),
|
||||
Text(product.productCode),
|
||||
Text(product.productName),
|
||||
Text(product.vendor?.vendorName ?? '-'),
|
||||
Text(product.uom?.uomName ?? '-'),
|
||||
Text(product.isActive ? 'Y' : 'N'),
|
||||
Text(product.isDeleted ? 'Y' : '-'),
|
||||
Text(product.note?.isEmpty ?? true ? '-' : product.note!),
|
||||
Text(
|
||||
product.updatedAt == null
|
||||
? '-'
|
||||
: dateFormat.format(product.updatedAt!.toLocal()),
|
||||
),
|
||||
],
|
||||
)
|
||||
.toList(),
|
||||
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: onProductTap == null
|
||||
? null
|
||||
: (index) => onProductTap!(products[index]),
|
||||
columnSpanExtent: (index) => switch (index) {
|
||||
2 => const FixedTableSpanExtent(200),
|
||||
3 => const FixedTableSpanExtent(180),
|
||||
7 => const FixedTableSpanExtent(220),
|
||||
8 => const FixedTableSpanExtent(160),
|
||||
_ => const FixedTableSpanExtent(120),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user