전역 구조 리팩터링 및 테스트 확장

This commit is contained in:
JiWoong Sul
2025-09-29 01:51:47 +09:00
parent c00c0c9ab2
commit fef7108479
70 changed files with 7709 additions and 3185 deletions

View File

@@ -6,6 +6,7 @@ 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/features/util/postal_search/presentation/models/postal_search_result.dart';
import 'package:superport_v2/features/util/postal_search/presentation/widgets/postal_search_dialog.dart';
@@ -198,6 +199,33 @@ class _CustomerEnabledPageState extends State<_CustomerEnabledPage> {
),
],
toolbar: FilterBar(
actions: [
ShadButton.outline(
onPressed: _controller.isLoading ? null : _applyFilters,
child: const Text('검색 적용'),
),
if (showReset)
ShadButton.ghost(
onPressed: _controller.isLoading
? null
: () {
_searchController.clear();
_searchFocus.requestFocus();
_controller.updateQuery('');
_controller.updateTypeFilter(CustomerTypeFilter.all);
_controller.updateStatusFilter(
CustomerStatusFilter.all,
);
_updateRoute(
page: 1,
queryOverride: '',
typeOverride: CustomerTypeFilter.all,
statusOverride: CustomerStatusFilter.all,
);
},
child: const Text('초기화'),
),
],
children: [
SizedBox(
width: 260,
@@ -251,31 +279,6 @@ class _CustomerEnabledPageState extends State<_CustomerEnabledPage> {
.toList(),
),
),
ShadButton.outline(
onPressed: _controller.isLoading ? null : _applyFilters,
child: const Text('검색 적용'),
),
if (showReset)
ShadButton.ghost(
onPressed: _controller.isLoading
? null
: () {
_searchController.clear();
_searchFocus.requestFocus();
_controller.updateQuery('');
_controller.updateTypeFilter(CustomerTypeFilter.all);
_controller.updateStatusFilter(
CustomerStatusFilter.all,
);
_updateRoute(
page: 1,
queryOverride: '',
typeOverride: CustomerTypeFilter.all,
statusOverride: CustomerStatusFilter.all,
);
},
child: const Text('초기화'),
),
],
),
child: ShadCard(
@@ -515,395 +518,427 @@ class _CustomerEnabledPageState extends State<_CustomerEnabledPage> {
final codeError = ValueNotifier<String?>(null);
final nameError = ValueNotifier<String?>(null);
final typeError = ValueNotifier<String?>(null);
final zipcodeError = ValueNotifier<String?>(null);
await showDialog<bool>(
context: parentContext,
builder: (dialogContext) {
final theme = ShadTheme.of(dialogContext);
final materialTheme = Theme.of(dialogContext);
final navigator = Navigator.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;
}
zipcodeController
..text = result.zipcode
..selection = TextSelection.collapsed(
offset: result.zipcode.length,
);
selectedPostalNotifier.value = result;
if (result.fullAddress.isNotEmpty) {
addressController
..text = result.fullAddress
..selection = TextSelection.collapsed(
offset: addressController.text.length,
);
}
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;
}
}
return Dialog(
insetPadding: const EdgeInsets.all(24),
clipBehavior: Clip.antiAlias,
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 560),
child: ShadCard(
title: Text(
isEdit ? '고객사 수정' : '고객사 등록',
style: theme.textTheme.h3,
),
description: Text(
'고객사 기본 정보를 ${isEdit ? '수정' : '입력'}하세요.',
style: theme.textTheme.muted,
),
footer: ValueListenableBuilder<bool>(
valueListenable: saving,
builder: (_, isSaving, __) {
return Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
ShadButton.ghost(
onPressed: isSaving ? null : () => navigator.pop(false),
child: const Text('취소'),
),
const SizedBox(width: 12),
ShadButton(
onPressed: isSaving
? null
: () async {
final code = codeController.text.trim();
final name = nameController.text.trim();
final email = emailController.text.trim();
final mobile = mobileController.text.trim();
final zipcode = zipcodeController.text.trim();
final address = addressController.text.trim();
final note = noteController.text.trim();
final partner = partnerNotifier.value;
var general = generalNotifier.value;
void handlePostalSelectionChange() {
if (selectedPostalNotifier.value != null) {
zipcodeError.value = null;
}
}
codeError.value = code.isEmpty
? '고객사코드를 입력하세요.'
: null;
nameError.value = name.isEmpty
? '고객사명을 입력하세요.'
: null;
zipcodeController.addListener(handleZipcodeChange);
selectedPostalNotifier.addListener(handlePostalSelectionChange);
if (!partner && !general) {
general = true;
generalNotifier.value = true;
}
Future<void> openPostalSearch(BuildContext dialogContext) 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,
);
}
}
typeError.value = (!partner && !general)
? '파트너/일반 중 하나 이상 선택하세요.'
: 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 email = emailController.text.trim();
final mobile = mobileController.text.trim();
final zipcode = zipcodeController.text.trim();
final address = addressController.text.trim();
final note = noteController.text.trim();
final partner = partnerNotifier.value;
var general = generalNotifier.value;
final selectedPostal = selectedPostalNotifier.value;
if (codeError.value != null ||
nameError.value != null ||
typeError.value != null) {
return;
}
codeError.value = code.isEmpty ? '고객사코드를 입력하세요.' : null;
nameError.value = name.isEmpty ? '고객사명을 입력하세요.' : null;
zipcodeError.value =
zipcode.isNotEmpty && selectedPostal == null
? '우편번호 검색으로 주소를 선택하세요.'
: null;
saving.value = true;
final input = CustomerInput(
customerCode: code,
customerName: name,
isPartner: partner,
isGeneral: general,
email: email.isEmpty ? null : email,
mobileNo: mobile.isEmpty ? null : mobile,
zipcode: zipcode.isEmpty ? null : zipcode,
addressDetail: address.isEmpty
? null
: address,
isActive: isActiveNotifier.value,
note: note.isEmpty ? null : note,
);
final response = isEdit
? await _controller.update(
customerId!,
input,
)
: await _controller.create(input);
saving.value = false;
if (response != null) {
if (!navigator.mounted) {
return;
}
if (mounted) {
_showSnack(
isEdit ? '고객사를 수정했습니다.' : '고객사를 등록했습니다.',
);
}
navigator.pop(true);
if (!partner && !general) {
general = true;
generalNotifier.value = true;
}
typeError.value = (!partner && !general)
? '파트너/일반 중 하나 이상 선택하세요.'
: null;
if (codeError.value != null ||
nameError.value != null ||
zipcodeError.value != null ||
typeError.value != null) {
return;
}
saving.value = true;
final input = CustomerInput(
customerCode: code,
customerName: name,
isPartner: partner,
isGeneral: general,
email: email.isEmpty ? null : email,
mobileNo: mobile.isEmpty ? null : mobile,
zipcode: zipcode.isEmpty ? null : zipcode,
addressDetail: address.isEmpty ? null : address,
isActive: isActiveNotifier.value,
note: note.isEmpty ? null : note,
);
final navigator = Navigator.of(context);
final response = isEdit
? await _controller.update(customerId!, input)
: await _controller.create(input);
saving.value = false;
if (response != null) {
if (!navigator.mounted) {
return;
}
if (mounted) {
_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).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(
padding: const EdgeInsets.only(right: 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
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;
}
},
child: Text(isEdit ? '저장' : '등록'),
),
],
);
},
),
child: SingleChildScrollView(
padding: const EdgeInsets.only(right: 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
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,
),
),
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: 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: partnerNotifier,
builder: (_, partner, __) {
return ValueListenableBuilder<bool>(
valueListenable: generalNotifier,
builder: (_, general, __) {
return ValueListenableBuilder<String?>(
valueListenable: typeError,
builder: (_, errorText, __) {
final onChanged = saving.value
? null
: (bool? value) {
if (value == null) return;
partnerNotifier.value = value;
if (!value && !generalNotifier.value) {
typeError.value =
'파트너/일반 중 하나 이상 선택하세요.';
} else {
typeError.value = null;
}
};
final onChangedGeneral = saving.value
? null
: (bool? value) {
if (value == null) return;
generalNotifier.value = value;
if (!value && !partnerNotifier.value) {
typeError.value =
'파트너/일반 중 하나 이상 선택하세요.';
} else {
typeError.value = null;
}
};
return _FormField(
label: '유형',
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Row(
children: [
ShadCheckbox(
value: partner,
onChanged: onChanged,
),
const SizedBox(width: 8),
const Text('파트너'),
const SizedBox(width: 24),
ShadCheckbox(
value: general,
onChanged: onChangedGeneral,
),
const SizedBox(width: 8),
const Text('일반'),
],
),
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: partnerNotifier,
builder: (_, partner, __) {
return ValueListenableBuilder<bool>(
valueListenable: generalNotifier,
builder: (_, general, __) {
return ValueListenableBuilder<String?>(
valueListenable: typeError,
builder: (_, errorText, __) {
final onChanged = isSaving
? null
: (bool? value) {
if (value == null) return;
partnerNotifier.value = value;
if (!value && !generalNotifier.value) {
typeError.value =
'파트너/일반 중 하나 이상 선택하세요.';
} else {
typeError.value = null;
}
};
final onChangedGeneral = isSaving
? null
: (bool? value) {
if (value == null) return;
generalNotifier.value = value;
if (!value && !partnerNotifier.value) {
typeError.value =
'파트너/일반 중 하나 이상 선택하세요.';
} else {
typeError.value = null;
}
};
return _FormField(
label: '유형',
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
ShadCheckbox(
value: partner,
onChanged: onChanged,
),
const SizedBox(width: 8),
const Text('파트너'),
const SizedBox(width: 24),
ShadCheckbox(
value: general,
onChanged: onChangedGeneral,
),
const SizedBox(width: 8),
const Text('일반'),
],
),
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),
_FormField(
label: '이메일',
child: ShadInput(
controller: emailController,
keyboardType: TextInputType.emailAddress,
),
),
const SizedBox(height: 16),
_FormField(
label: '연락처',
child: ShadInput(
controller: mobileController,
keyboardType: TextInputType.phone,
),
),
const SizedBox(height: 16),
_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),
ShadButton.outline(
onPressed: saving.value
? 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,
);
},
),
],
),
);
},
);
},
),
const SizedBox(height: 16),
_FormField(
label: '이메일',
child: ShadInput(
controller: emailController,
keyboardType: TextInputType.emailAddress,
),
const SizedBox(height: 16),
_FormField(
label: '상세주소',
child: ShadInput(
controller: addressController,
placeholder: const Text('상세주소 입력'),
),
),
const SizedBox(height: 16),
_FormField(
label: '연락처',
child: ShadInput(
controller: mobileController,
keyboardType: TextInputType.phone,
),
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(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),
ShadButton.outline(
onPressed: isSaving
? null
: () => openPostalSearch(context),
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(width: 8),
Text(value ? '사용' : '미사용'),
],
),
);
},
],
),
);
},
),
const SizedBox(height: 16),
_FormField(
label: '상세주소',
child: ShadInput(
controller: addressController,
placeholder: const Text('상세주소 입력'),
),
const SizedBox(height: 16),
_FormField(
label: '비고',
child: ShadTextarea(controller: noteController),
),
if (existing != null) ..._buildAuditInfo(existing, theme),
],
),
),
const SizedBox(height: 16),
ValueListenableBuilder<bool>(
valueListenable: isActiveNotifier,
builder: (_, value, __) {
return _FormField(
label: '사용여부',
child: Row(
children: [
ShadSwitch(
value: value,
onChanged: isSaving
? null
: (next) => isActiveNotifier.value = next,
),
const SizedBox(width: 8),
Text(value ? '사용' : '미사용'),
],
),
);
},
),
const SizedBox(height: 16),
_FormField(
label: '비고',
child: ShadTextarea(controller: noteController),
),
if (existing != null) ..._buildAuditInfo(existing, theme),
],
),
),
),
);
},
);
},
),
),
);
zipcodeController.removeListener(handleZipcodeChange);
selectedPostalNotifier.removeListener(handlePostalSelectionChange);
codeController.dispose();
nameController.dispose();
@@ -920,27 +955,26 @@ class _CustomerEnabledPageState extends State<_CustomerEnabledPage> {
codeError.dispose();
nameError.dispose();
typeError.dispose();
zipcodeError.dispose();
}
Future<void> _confirmDelete(Customer customer) async {
final confirmed = await showDialog<bool>(
final confirmed = await SuperportDialog.show<bool>(
context: context,
builder: (dialogContext) {
return AlertDialog(
title: const Text('고객사 삭제'),
content: Text('"${customer.customerName}" 고객사를 삭제하시겠습니까?'),
actions: [
TextButton(
onPressed: () => Navigator.of(dialogContext).pop(false),
child: const Text('취소'),
),
TextButton(
onPressed: () => Navigator.of(dialogContext).pop(true),
child: const Text('삭제'),
),
],
);
},
dialog: SuperportDialog(
title: '고객사 삭제',
description: '"${customer.customerName}" 고객사 삭제하시겠습니까?',
actions: [
ShadButton.ghost(
onPressed: () => Navigator.of(context).pop(false),
child: const Text('취소'),
),
ShadButton(
onPressed: () => Navigator.of(context).pop(true),
child: const Text('삭제'),
),
],
),
);
if (confirmed == true && customer.id != null) {

View File

@@ -5,6 +5,7 @@ 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 '../../../../../core/config/environment.dart';
import '../../../../../widgets/spec_page.dart';
@@ -130,7 +131,8 @@ class _GroupEnabledPageState extends State<_GroupEnabledPage> {
? false
: (result.page * result.pageSize) < result.total;
final showReset = _searchController.text.isNotEmpty ||
final showReset =
_searchController.text.isNotEmpty ||
_controller.defaultFilter != GroupDefaultFilter.all ||
_controller.statusFilter != GroupStatusFilter.all;
@@ -145,12 +147,35 @@ class _GroupEnabledPageState extends State<_GroupEnabledPage> {
actions: [
ShadButton(
leading: const Icon(LucideIcons.plus, size: 16),
onPressed:
_controller.isSubmitting ? null : () => _openGroupForm(context),
onPressed: _controller.isSubmitting
? null
: () => _openGroupForm(context),
child: const Text('신규 등록'),
),
],
toolbar: FilterBar(
actions: [
ShadButton.outline(
onPressed: _controller.isLoading ? null : _applyFilters,
child: const Text('검색 적용'),
),
if (showReset)
ShadButton.ghost(
onPressed: _controller.isLoading
? null
: () {
_searchController.clear();
_searchFocus.requestFocus();
_controller.updateQuery('');
_controller.updateDefaultFilter(
GroupDefaultFilter.all,
);
_controller.updateStatusFilter(GroupStatusFilter.all);
_controller.fetch(page: 1);
},
child: const Text('초기화'),
),
],
children: [
SizedBox(
width: 260,
@@ -206,28 +231,6 @@ class _GroupEnabledPageState extends State<_GroupEnabledPage> {
.toList(),
),
),
ShadButton.outline(
onPressed: _controller.isLoading ? null : _applyFilters,
child: const Text('검색 적용'),
),
if (showReset)
ShadButton.ghost(
onPressed: _controller.isLoading
? null
: () {
_searchController.clear();
_searchFocus.requestFocus();
_controller.updateQuery('');
_controller.updateDefaultFilter(
GroupDefaultFilter.all,
);
_controller.updateStatusFilter(
GroupStatusFilter.all,
);
_controller.fetch(page: 1);
},
child: const Text('초기화'),
),
],
),
child: ShadCard(
@@ -272,26 +275,22 @@ class _GroupEnabledPageState extends State<_GroupEnabledPage> {
child: Center(child: CircularProgressIndicator()),
)
: groups.isEmpty
? Padding(
padding: const EdgeInsets.all(32),
child: Text(
'조건에 맞는 그룹이 없습니다.',
style: theme.textTheme.muted,
),
)
: _GroupTable(
groups: groups,
dateFormat: _dateFormat,
onEdit: _controller.isSubmitting
? null
: (group) => _openGroupForm(context, group: group),
onDelete: _controller.isSubmitting
? null
: _confirmDelete,
onRestore: _controller.isSubmitting
? null
: _restoreGroup,
),
? Padding(
padding: const EdgeInsets.all(32),
child: Text(
'조건에 맞는 그룹이 없습니다.',
style: theme.textTheme.muted,
),
)
: _GroupTable(
groups: groups,
dateFormat: _dateFormat,
onEdit: _controller.isSubmitting
? null
: (group) => _openGroupForm(context, group: group),
onDelete: _controller.isSubmitting ? null : _confirmDelete,
onRestore: _controller.isSubmitting ? null : _restoreGroup,
),
),
);
},
@@ -352,199 +351,185 @@ class _GroupEnabledPageState extends State<_GroupEnabledPage> {
final saving = ValueNotifier<bool>(false);
final nameError = ValueNotifier<String?>(null);
await showDialog<bool>(
await SuperportDialog.show<void>(
context: context,
builder: (dialogContext) {
final theme = ShadTheme.of(dialogContext);
final materialTheme = Theme.of(dialogContext);
final navigator = Navigator.of(dialogContext);
return Dialog(
insetPadding: const EdgeInsets.all(24),
clipBehavior: Clip.antiAlias,
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 540),
child: ShadCard(
title: Text(
isEdit ? '그룹 수정' : '그룹 등록',
style: theme.textTheme.h3,
),
description: Text(
'그룹 정보를 ${isEdit ? '수정' : '입력'}하세요.',
style: theme.textTheme.muted,
),
footer: ValueListenableBuilder<bool>(
valueListenable: saving,
builder: (_, isSaving, __) {
return Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
ShadButton.ghost(
onPressed: isSaving ? null : () => navigator.pop(false),
child: const Text('취소'),
),
const SizedBox(width: 12),
ShadButton(
onPressed: isSaving
? null
: () async {
final name = nameController.text.trim();
final description = descriptionController.text
.trim();
final note = noteController.text.trim();
dialog: SuperportDialog(
title: isEdit ? '그룹 수정' : '그룹 등록',
description: '그룹 정보를 ${isEdit ? '수정' : '입력'}하세요.',
constraints: const BoxConstraints(maxWidth: 540),
actions: [
ValueListenableBuilder<bool>(
valueListenable: saving,
builder: (dialogContext, isSaving, __) {
return ShadButton.ghost(
onPressed: isSaving
? null
: () => Navigator.of(dialogContext).pop(),
child: const Text('취소'),
);
},
),
ValueListenableBuilder<bool>(
valueListenable: saving,
builder: (dialogContext, isSaving, __) {
return ShadButton(
onPressed: isSaving
? null
: () async {
final name = nameController.text.trim();
final description = descriptionController.text.trim();
final note = noteController.text.trim();
nameError.value = name.isEmpty
? '그룹명을 입력하세요.'
: null;
nameError.value = name.isEmpty ? '그룹명을 입력하세요.' : null;
if (nameError.value != null) {
return;
}
if (nameError.value != null) {
return;
}
saving.value = true;
final input = GroupInput(
groupName: name,
description: description.isEmpty
? null
: description,
isDefault: isDefaultNotifier.value,
isActive: isActiveNotifier.value,
note: note.isEmpty ? null : note,
);
final response = isEdit
? await _controller.update(groupId!, input)
: await _controller.create(input);
saving.value = false;
if (response != null) {
if (!navigator.mounted) {
return;
saving.value = true;
final input = GroupInput(
groupName: name,
description: description.isEmpty ? null : description,
isDefault: isDefaultNotifier.value,
isActive: isActiveNotifier.value,
note: note.isEmpty ? null : note,
);
final navigator = Navigator.of(dialogContext);
final response = isEdit
? await _controller.update(groupId!, input)
: await _controller.create(input);
saving.value = false;
if (response != null) {
if (!navigator.mounted) {
return;
}
if (mounted) {
_showSnack(isEdit ? '그룹을 수정했습니다.' : '그룹을 등록했습니다.');
}
navigator.pop();
}
},
child: Text(isEdit ? '저장' : '등록'),
);
},
),
],
child: StatefulBuilder(
builder: (dialogContext, _) {
final theme = ShadTheme.of(dialogContext);
final materialTheme = Theme.of(dialogContext);
return SizedBox(
width: double.infinity,
child: SingleChildScrollView(
padding: const EdgeInsets.only(right: 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
ValueListenableBuilder<String?>(
valueListenable: nameError,
builder: (_, errorText, __) {
return _FormField(
label: '그룹명',
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ShadInput(
controller: nameController,
readOnly: isEdit,
onChanged: (_) {
if (nameController.text.trim().isNotEmpty) {
nameError.value = null;
}
if (mounted) {
_showSnack(
isEdit ? '그룹을 수정했습니다.' : '그룹을 등록했습니다.',
);
}
navigator.pop(true);
}
},
child: Text(isEdit ? '저장' : '등록'),
),
],
);
},
),
child: SizedBox(
width: double.infinity,
child: SingleChildScrollView(
padding: const EdgeInsets.only(right: 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
ValueListenableBuilder<String?>(
valueListenable: nameError,
builder: (_, errorText, __) {
return _FormField(
label: '그룹명',
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ShadInput(
controller: nameController,
readOnly: isEdit,
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,
),
},
),
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),
_FormField(
label: '설명',
child: ShadTextarea(controller: descriptionController),
),
const SizedBox(height: 16),
ValueListenableBuilder<bool>(
valueListenable: isDefaultNotifier,
builder: (_, value, __) {
return _FormField(
label: '기본여부',
child: Row(
children: [
ShadSwitch(
value: value,
onChanged: saving.value
? null
: (next) =>
isDefaultNotifier.value = next,
),
const SizedBox(width: 8),
Text(value ? '기본 그룹' : '일반 그룹'),
],
),
);
},
],
),
);
},
),
const SizedBox(height: 16),
_FormField(
label: '설명',
child: ShadTextarea(controller: descriptionController),
),
const SizedBox(height: 16),
ValueListenableBuilder<bool>(
valueListenable: isDefaultNotifier,
builder: (_, value, __) {
return _FormField(
label: '기본여부',
child: Row(
children: [
ShadSwitch(
value: value,
onChanged: saving.value
? null
: (next) => isDefaultNotifier.value = next,
),
const SizedBox(width: 8),
Text(value ? '기본 그룹' : '일반 그룹'),
],
),
);
},
),
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 (existingGroup != null) ...[
const SizedBox(height: 20),
Text(
'생성일시: ${_formatDateTime(existingGroup.createdAt)}',
style: theme.textTheme.small,
),
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: 4),
Text(
'수정일시: ${_formatDateTime(existingGroup.updatedAt)}',
style: theme.textTheme.small,
),
const SizedBox(height: 16),
_FormField(
label: '비고',
child: ShadTextarea(controller: noteController),
),
if (isEdit) ...[
const SizedBox(height: 20),
Text(
'생성일시: ${_formatDateTime(existingGroup.createdAt)}',
style: theme.textTheme.small,
),
const SizedBox(height: 4),
Text(
'수정일시: ${_formatDateTime(existingGroup.updatedAt)}',
style: theme.textTheme.small,
),
],
],
),
],
),
),
),
),
);
},
);
},
),
),
);
nameController.dispose();

View File

@@ -6,6 +6,7 @@ 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 '../../../../../core/config/environment.dart';
import '../../../../../widgets/spec_page.dart';
@@ -167,7 +168,8 @@ class _GroupPermissionEnabledPageState
? false
: (result.page * result.pageSize) < result.total;
final showReset = _searchController.text.isNotEmpty ||
final showReset =
_searchController.text.isNotEmpty ||
_controller.groupFilter != null ||
_controller.menuFilter != null ||
_controller.statusFilter != GroupPermissionStatusFilter.all ||
@@ -191,6 +193,29 @@ class _GroupPermissionEnabledPageState
),
],
toolbar: FilterBar(
actions: [
ShadButton.outline(
onPressed: _controller.isLoading ? null : _applyFilters,
child: const Text('검색 적용'),
),
if (showReset)
ShadButton.ghost(
onPressed: _controller.isLoading
? null
: () {
_searchController.clear();
_searchFocus.requestFocus();
_controller.updateGroupFilter(null);
_controller.updateMenuFilter(null);
_controller.updateIncludeDeleted(false);
_controller.updateStatusFilter(
GroupPermissionStatusFilter.all,
);
_controller.fetch(page: 1);
},
child: const Text('초기화'),
),
],
children: [
SizedBox(
width: 260,
@@ -208,16 +233,12 @@ class _GroupPermissionEnabledPageState
key: ValueKey(_controller.groupFilter),
initialValue: _controller.groupFilter,
placeholder: Text(
_controller.groups.isEmpty
? '그룹 로딩중...'
: '그룹 전체',
_controller.groups.isEmpty ? '그룹 로딩중...' : '그룹 전체',
),
selectedOptionBuilder: (context, value) {
if (value == null) {
return Text(
_controller.groups.isEmpty
? '그룹 로딩중...'
: '그룹 전체',
_controller.groups.isEmpty ? '그룹 로딩중...' : '그룹 전체',
);
}
final group = _controller.groups.firstWhere(
@@ -230,10 +251,7 @@ class _GroupPermissionEnabledPageState
_controller.updateGroupFilter(value);
},
options: [
const ShadOption<int?>(
value: null,
child: Text('그룹 전체'),
),
const ShadOption<int?>(value: null, child: Text('그룹 전체')),
..._controller.groups.map(
(group) => ShadOption<int?>(
value: group.id,
@@ -249,25 +267,18 @@ class _GroupPermissionEnabledPageState
key: ValueKey(_controller.menuFilter),
initialValue: _controller.menuFilter,
placeholder: Text(
_controller.menus.isEmpty
? '메뉴 로딩중...'
: '메뉴 전체',
_controller.menus.isEmpty ? '메뉴 로딩중...' : '메뉴 전체',
),
selectedOptionBuilder: (context, value) {
if (value == null) {
return Text(
_controller.menus.isEmpty
? '메뉴 로딩중...'
: '메뉴 전체',
_controller.menus.isEmpty ? '메뉴 로딩중...' : '메뉴 전체',
);
}
final menuItem = _controller.menus.firstWhere(
(m) => m.id == value,
orElse: () => MenuItem(
id: value,
menuCode: '',
menuName: '',
),
orElse: () =>
MenuItem(id: value, menuCode: '', menuName: ''),
);
return Text(menuItem.menuName);
},
@@ -275,10 +286,7 @@ class _GroupPermissionEnabledPageState
_controller.updateMenuFilter(value);
},
options: [
const ShadOption<int?>(
value: null,
child: Text('메뉴 전체'),
),
const ShadOption<int?>(value: null, child: Text('메뉴 전체')),
..._controller.menus.map(
(menuItem) => ShadOption<int?>(
value: menuItem.id,
@@ -322,24 +330,6 @@ class _GroupPermissionEnabledPageState
const Text('삭제 포함'),
],
),
ShadButton.outline(
onPressed: _controller.isLoading ? null : _applyFilters,
child: const Text('검색 적용'),
),
if (showReset)
ShadButton.ghost(
onPressed: _controller.isLoading
? null
: () {
_searchController.clear();
_searchFocus.requestFocus();
_controller.updateGroupFilter(null);
_controller.updateMenuFilter(null);
_controller.updateIncludeDeleted(false);
_controller.fetch(page: 1);
},
child: const Text('초기화'),
),
],
),
child: ShadCard(
@@ -384,27 +374,27 @@ class _GroupPermissionEnabledPageState
child: Center(child: CircularProgressIndicator()),
)
: permissions.isEmpty
? Padding(
padding: const EdgeInsets.all(32),
child: Text(
'조건에 맞는 권한이 없습니다.',
style: theme.textTheme.muted,
),
)
: _PermissionTable(
permissions: permissions,
dateFormat: _dateFormat,
onEdit: _controller.isSubmitting
? null
: (permission) =>
_openPermissionForm(context, permission: permission),
onDelete: _controller.isSubmitting
? null
: _confirmDelete,
onRestore: _controller.isSubmitting
? null
: _restorePermission,
),
? Padding(
padding: const EdgeInsets.all(32),
child: Text(
'조건에 맞는 권한이 없습니다.',
style: theme.textTheme.muted,
),
)
: _PermissionTable(
permissions: permissions,
dateFormat: _dateFormat,
onEdit: _controller.isSubmitting
? null
: (permission) => _openPermissionForm(
context,
permission: permission,
),
onDelete: _controller.isSubmitting ? null : _confirmDelete,
onRestore: _controller.isSubmitting
? null
: _restorePermission,
),
),
);
},
@@ -430,311 +420,302 @@ class _GroupPermissionEnabledPageState
BuildContext context, {
GroupPermission? permission,
}) async {
final isEdit = permission != null;
final permissionId = permission?.id;
final existingPermission = permission;
final isEdit = existingPermission != null;
final permissionId = existingPermission?.id;
if (isEdit && permissionId == null) {
_showSnack('ID 정보가 없어 수정할 수 없습니다.');
return;
}
final groupNotifier = ValueNotifier<int?>(permission?.group.id);
final menuNotifier = ValueNotifier<int?>(permission?.menu.id);
final createNotifier = ValueNotifier<bool>(permission?.canCreate ?? false);
final readNotifier = ValueNotifier<bool>(permission?.canRead ?? true);
final updateNotifier = ValueNotifier<bool>(permission?.canUpdate ?? false);
final deleteNotifier = ValueNotifier<bool>(permission?.canDelete ?? false);
final activeNotifier = ValueNotifier<bool>(permission?.isActive ?? true);
final noteController = TextEditingController(text: permission?.note ?? '');
final groupNotifier = ValueNotifier<int?>(existingPermission?.group.id);
final menuNotifier = ValueNotifier<int?>(existingPermission?.menu.id);
final createNotifier = ValueNotifier<bool>(
existingPermission?.canCreate ?? false,
);
final readNotifier = ValueNotifier<bool>(
existingPermission?.canRead ?? true,
);
final updateNotifier = ValueNotifier<bool>(
existingPermission?.canUpdate ?? false,
);
final deleteNotifier = ValueNotifier<bool>(
existingPermission?.canDelete ?? false,
);
final activeNotifier = ValueNotifier<bool>(
existingPermission?.isActive ?? true,
);
final noteController = TextEditingController(
text: existingPermission?.note ?? '',
);
final saving = ValueNotifier<bool>(false);
final groupError = ValueNotifier<String?>(null);
final menuError = ValueNotifier<String?>(null);
await showDialog<bool>(
await SuperportDialog.show<bool>(
context: context,
builder: (dialogContext) {
final theme = ShadTheme.of(dialogContext);
final materialTheme = Theme.of(dialogContext);
final navigator = Navigator.of(dialogContext);
return Dialog(
insetPadding: const EdgeInsets.all(24),
clipBehavior: Clip.antiAlias,
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 600),
child: ShadCard(
title: Text(
isEdit ? '권한 수정' : '권한 등록',
style: theme.textTheme.h3,
),
description: Text(
'그룹과 메뉴의 권한을 ${isEdit ? '수정' : '등록'}하세요.',
style: theme.textTheme.muted,
),
footer: ValueListenableBuilder<bool>(
valueListenable: saving,
builder: (_, isSaving, __) {
return Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
ShadButton.ghost(
onPressed: isSaving ? null : () => navigator.pop(false),
child: const Text('취소'),
),
const SizedBox(width: 12),
ShadButton(
onPressed: isSaving
? null
: () async {
final groupId = groupNotifier.value;
final menuId = menuNotifier.value;
groupError.value = groupId == null
? '그룹을 선택하세요.'
: null;
menuError.value = menuId == null
? '메뉴를 선택하세요.'
: null;
if (groupError.value != null ||
menuError.value != null) {
return;
}
dialog: SuperportDialog(
title: isEdit ? '권한 수정' : '권한 등록',
description: '그룹과 메뉴의 권한을 ${isEdit ? '수정' : '등록'}하세요.',
constraints: const BoxConstraints(maxWidth: 600),
secondaryAction: ValueListenableBuilder<bool>(
valueListenable: saving,
builder: (dialogContext, isSaving, __) {
return ShadButton.ghost(
onPressed: isSaving
? null
: () => Navigator.of(dialogContext).pop(false),
child: const Text('취소'),
);
},
),
primaryAction: ValueListenableBuilder<bool>(
valueListenable: saving,
builder: (dialogContext, isSaving, __) {
return ShadButton(
onPressed: isSaving
? null
: () async {
final groupId = groupNotifier.value;
final menuId = menuNotifier.value;
groupError.value = groupId == null ? '그룹을 선택하세요.' : null;
menuError.value = menuId == null ? '메뉴를 선택하세요.' : null;
if (groupError.value != null || menuError.value != null) {
return;
}
saving.value = true;
final input = GroupPermissionInput(
groupId: groupId!,
menuId: menuId!,
canCreate: createNotifier.value,
canRead: readNotifier.value,
canUpdate: updateNotifier.value,
canDelete: deleteNotifier.value,
isActive: activeNotifier.value,
note: noteController.text.trim().isEmpty
? null
: noteController.text.trim(),
);
final response = isEdit
? await _controller.update(
permissionId!,
input,
)
: await _controller.create(input);
saving.value = false;
if (response != null) {
if (!navigator.mounted) {
return;
}
if (mounted) {
_showSnack(
isEdit ? '권한을 수정했습니다.' : '권한을 등록했습니다.',
);
}
navigator.pop(true);
saving.value = true;
final trimmedNote = noteController.text.trim();
final input = GroupPermissionInput(
groupId: groupId!,
menuId: menuId!,
canCreate: createNotifier.value,
canRead: readNotifier.value,
canUpdate: updateNotifier.value,
canDelete: deleteNotifier.value,
isActive: activeNotifier.value,
note: trimmedNote.isEmpty ? null : trimmedNote,
);
final navigator = Navigator.of(dialogContext);
final response = isEdit
? await _controller.update(permissionId!, input)
: await _controller.create(input);
saving.value = false;
if (response != null) {
if (!navigator.mounted) {
return;
}
if (mounted) {
_showSnack(isEdit ? '권한을 수정했습니다.' : '권한을 등록했습니다.');
}
navigator.pop(true);
}
},
child: Text(isEdit ? '저장' : '등록'),
);
},
),
child: ValueListenableBuilder<bool>(
valueListenable: saving,
builder: (dialogContext, isSaving, __) {
final theme = ShadTheme.of(dialogContext);
final materialTheme = Theme.of(dialogContext);
return SingleChildScrollView(
padding: const EdgeInsets.only(right: 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
ValueListenableBuilder<String?>(
valueListenable: groupError,
builder: (_, errorText, __) {
return _FormField(
label: '그룹',
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ShadSelect<int?>(
initialValue: groupNotifier.value,
placeholder: const Text('그룹을 선택하세요'),
selectedOptionBuilder: (context, value) {
if (value == null) {
return const Text('그룹을 선택하세요');
}
final groupId = value;
final group = _controller.groups.firstWhere(
(g) => g.id == groupId,
orElse: () =>
Group(id: groupId, groupName: ''),
);
return Text(
group.groupName.isEmpty
? '그룹을 선택하세요'
: group.groupName,
);
},
child: Text(isEdit ? '저장' : '등록'),
),
],
);
},
),
child: SizedBox(
width: double.infinity,
child: SingleChildScrollView(
padding: const EdgeInsets.only(right: 12),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
ValueListenableBuilder<String?>(
valueListenable: groupError,
builder: (_, errorText, __) {
return _FormField(
label: '그룹',
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ShadSelect<int?>(
initialValue: groupNotifier.value,
placeholder: const Text('그룹을 선택하세요'),
selectedOptionBuilder: (context, value) {
if (value == null) {
return const Text('그룹을 선택하세요');
}
final groupId = value;
final group = _controller.groups.firstWhere(
(g) => g.id == groupId,
orElse: () =>
Group(id: groupId, groupName: ''),
);
return Text(
group.groupName.isEmpty
? '그룹을 선택하세요'
: group.groupName,
);
},
onChanged: saving.value || isEdit
? null
: (value) {
groupNotifier.value = value;
if (value != null) {
groupError.value = null;
}
},
options: [
..._controller.groups.map(
(group) => ShadOption<int?>(
value: group.id,
child: Text(group.groupName),
),
),
],
),
if (errorText != null)
Padding(
padding: const EdgeInsets.only(top: 6),
child: Text(
errorText,
style: theme.textTheme.small.copyWith(
color: materialTheme.colorScheme.error,
),
),
onChanged: isSaving || isEdit
? null
: (value) {
groupNotifier.value = value;
if (value != null) {
groupError.value = null;
}
},
options: [
..._controller.groups.map(
(group) => ShadOption<int?>(
value: group.id,
child: Text(group.groupName),
),
),
],
),
);
},
),
const SizedBox(height: 16),
ValueListenableBuilder<String?>(
valueListenable: menuError,
builder: (_, errorText, __) {
return _FormField(
label: '메뉴',
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ShadSelect<int?>(
initialValue: menuNotifier.value,
placeholder: const Text('메뉴를 선택하세요'),
selectedOptionBuilder: (context, value) {
if (value == null) {
return const Text('메뉴를 선택하세요');
}
final menuId = value;
final menu = _controller.menus.firstWhere(
(m) => m.id == menuId,
orElse: () => MenuItem(
id: menuId,
menuCode: '',
menuName: '',
),
);
return Text(
menu.menuName.isEmpty
? '메뉴를 선택하세요'
: menu.menuName,
);
},
onChanged: saving.value || isEdit
? null
: (value) {
menuNotifier.value = value;
if (value != null) {
menuError.value = null;
}
},
options: [
..._controller.menus.map(
(menu) => ShadOption<int?>(
value: menu.id,
child: Text(menu.menuName),
),
),
],
),
if (errorText != null)
Padding(
padding: const EdgeInsets.only(top: 6),
child: Text(
errorText,
style: theme.textTheme.small.copyWith(
color: materialTheme.colorScheme.error,
),
),
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: 20),
_PermissionToggleRow(
label: '생성권한',
notifier: createNotifier,
enabled: !saving.value,
),
const SizedBox(height: 12),
_PermissionToggleRow(
label: '조회권한',
notifier: readNotifier,
enabled: !saving.value,
),
const SizedBox(height: 12),
_PermissionToggleRow(
label: '수정권한',
notifier: updateNotifier,
enabled: !saving.value,
),
const SizedBox(height: 12),
_PermissionToggleRow(
label: '삭제권한',
notifier: deleteNotifier,
enabled: !saving.value,
),
const SizedBox(height: 16),
ValueListenableBuilder<bool>(
valueListenable: activeNotifier,
builder: (_, value, __) {
return _FormField(
label: '사용여부',
child: Row(
children: [
ShadSwitch(
value: value,
onChanged: saving.value
? null
: (next) => activeNotifier.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(permission.createdAt)}',
style: theme.textTheme.small,
),
],
),
const SizedBox(height: 4),
Text(
'수정일시: ${_formatDateTime(permission.updatedAt)}',
style: theme.textTheme.small,
),
],
],
);
},
),
),
const SizedBox(height: 16),
ValueListenableBuilder<String?>(
valueListenable: menuError,
builder: (_, errorText, __) {
return _FormField(
label: '메뉴',
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ShadSelect<int?>(
initialValue: menuNotifier.value,
placeholder: const Text('메뉴를 선택하세요'),
selectedOptionBuilder: (context, value) {
if (value == null) {
return const Text('메뉴를 선택하세요');
}
final menuId = value;
final menu = _controller.menus.firstWhere(
(m) => m.id == menuId,
orElse: () => MenuItem(
id: menuId,
menuCode: '',
menuName: '',
),
);
return Text(
menu.menuName.isEmpty
? '메뉴를 선택하세요'
: menu.menuName,
);
},
onChanged: isSaving || isEdit
? null
: (value) {
menuNotifier.value = value;
if (value != null) {
menuError.value = null;
}
},
options: [
..._controller.menus.map(
(menu) => ShadOption<int?>(
value: menu.id,
child: Text(menu.menuName),
),
),
],
),
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: 20),
_PermissionToggleRow(
label: '생성권한',
notifier: createNotifier,
enabled: !isSaving,
),
const SizedBox(height: 12),
_PermissionToggleRow(
label: '조회권한',
notifier: readNotifier,
enabled: !isSaving,
),
const SizedBox(height: 12),
_PermissionToggleRow(
label: '수정권한',
notifier: updateNotifier,
enabled: !isSaving,
),
const SizedBox(height: 12),
_PermissionToggleRow(
label: '삭제권한',
notifier: deleteNotifier,
enabled: !isSaving,
),
const SizedBox(height: 16),
ValueListenableBuilder<bool>(
valueListenable: activeNotifier,
builder: (_, value, __) {
return _FormField(
label: '사용여부',
child: Row(
children: [
ShadSwitch(
value: value,
onChanged: isSaving
? null
: (next) => activeNotifier.value = next,
),
const SizedBox(width: 8),
Text(value ? '사용' : '미사용'),
],
),
);
},
),
const SizedBox(height: 16),
_FormField(
label: '비고',
child: ShadTextarea(controller: noteController),
),
if (existingPermission != null) ...[
const SizedBox(height: 20),
Text(
'생성일시: ${_formatDateTime(existingPermission.createdAt)}',
style: theme.textTheme.small,
),
const SizedBox(height: 4),
Text(
'수정일시: ${_formatDateTime(existingPermission.updatedAt)}',
style: theme.textTheme.small,
),
],
],
),
),
),
);
},
);
},
),
),
);
groupNotifier.dispose();
@@ -751,26 +732,29 @@ class _GroupPermissionEnabledPageState
}
Future<void> _confirmDelete(GroupPermission permission) async {
final confirmed = await showDialog<bool>(
final confirmed = await SuperportDialog.show<bool>(
context: context,
builder: (dialogContext) {
return AlertDialog(
title: const Text('권한 삭제'),
content: Text(
dialog: SuperportDialog(
title: '권한 삭제',
description:
'"${permission.group.groupName}" → "${permission.menu.menuName}" 권한을 삭제하시겠습니까?',
),
actions: [
TextButton(
secondaryAction: Builder(
builder: (dialogContext) {
return ShadButton.ghost(
onPressed: () => Navigator.of(dialogContext).pop(false),
child: const Text('취소'),
),
TextButton(
);
},
),
primaryAction: Builder(
builder: (dialogContext) {
return ShadButton.destructive(
onPressed: () => Navigator.of(dialogContext).pop(true),
child: const Text('삭제'),
),
],
);
},
);
},
),
),
);
if (confirmed == true && permission.id != null) {

View File

@@ -5,6 +5,7 @@ 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 '../../../../../core/config/environment.dart';
import '../../../../../widgets/spec_page.dart';
@@ -151,7 +152,8 @@ class _MenuEnabledPageState extends State<_MenuEnabledPage> {
? false
: (result.page * result.pageSize) < result.total;
final showReset = _searchController.text.isNotEmpty ||
final showReset =
_searchController.text.isNotEmpty ||
_controller.parentFilter != null ||
_controller.statusFilter != menu.MenuStatusFilter.all ||
_controller.includeDeleted;
@@ -167,12 +169,36 @@ class _MenuEnabledPageState extends State<_MenuEnabledPage> {
actions: [
ShadButton(
leading: const Icon(LucideIcons.plus, size: 16),
onPressed:
_controller.isSubmitting ? null : () => _openMenuForm(context),
onPressed: _controller.isSubmitting
? null
: () => _openMenuForm(context),
child: const Text('신규 등록'),
),
],
toolbar: FilterBar(
actions: [
ShadButton.outline(
onPressed: _controller.isLoading ? null : _applyFilters,
child: const Text('검색 적용'),
),
if (showReset)
ShadButton.ghost(
onPressed: _controller.isLoading
? null
: () {
_searchController.clear();
_searchFocus.requestFocus();
_controller.updateQuery('');
_controller.updateParentFilter(null);
_controller.updateStatusFilter(
menu.MenuStatusFilter.all,
);
_controller.updateIncludeDeleted(false);
_controller.fetch(page: 1);
},
child: const Text('초기화'),
),
],
children: [
SizedBox(
width: 260,
@@ -195,18 +221,13 @@ class _MenuEnabledPageState extends State<_MenuEnabledPage> {
selectedOptionBuilder: (context, value) {
if (value == null) {
return Text(
_controller.isLoadingParents
? '상위 로딩중...'
: '상위 전체',
_controller.isLoadingParents ? '상위 로딩중...' : '상위 전체',
);
}
final target = _controller.parents.firstWhere(
(menuItem) => menuItem.id == value,
orElse: () => MenuItem(
id: value,
menuCode: '',
menuName: '',
),
orElse: () =>
MenuItem(id: value, menuCode: '', menuName: ''),
);
final label = target.menuName.isEmpty
? '상위 전체'
@@ -220,10 +241,7 @@ class _MenuEnabledPageState extends State<_MenuEnabledPage> {
_controller.fetch(page: 1);
},
options: [
const ShadOption<int?>(
value: null,
child: Text('상위 전체'),
),
const ShadOption<int?>(value: null, child: Text('상위 전체')),
..._controller.parents.map(
(menuItem) => ShadOption<int?>(
value: menuItem.id,
@@ -269,27 +287,6 @@ class _MenuEnabledPageState extends State<_MenuEnabledPage> {
const Text('삭제 포함'),
],
),
ShadButton.outline(
onPressed: _controller.isLoading ? null : _applyFilters,
child: const Text('검색 적용'),
),
if (showReset)
ShadButton.ghost(
onPressed: _controller.isLoading
? null
: () {
_searchController.clear();
_searchFocus.requestFocus();
_controller.updateQuery('');
_controller.updateParentFilter(null);
_controller.updateStatusFilter(
menu.MenuStatusFilter.all,
);
_controller.updateIncludeDeleted(false);
_controller.fetch(page: 1);
},
child: const Text('초기화'),
),
],
),
child: ShadCard(
@@ -334,27 +331,22 @@ class _MenuEnabledPageState extends State<_MenuEnabledPage> {
child: Center(child: CircularProgressIndicator()),
)
: menus.isEmpty
? Padding(
padding: const EdgeInsets.all(32),
child: Text(
'조건에 맞는 메뉴가 없습니다.',
style: theme.textTheme.muted,
),
)
: _MenuTable(
menus: menus,
dateFormat: _dateFormat,
onEdit: _controller.isSubmitting
? null
: (menuItem) =>
_openMenuForm(context, menu: menuItem),
onDelete: _controller.isSubmitting
? null
: _confirmDelete,
onRestore: _controller.isSubmitting
? null
: _restoreMenu,
),
? Padding(
padding: const EdgeInsets.all(32),
child: Text(
'조건에 맞는 메뉴가 없습니다.',
style: theme.textTheme.muted,
),
)
: _MenuTable(
menus: menus,
dateFormat: _dateFormat,
onEdit: _controller.isSubmitting
? null
: (menuItem) => _openMenuForm(context, menu: menuItem),
onDelete: _controller.isSubmitting ? null : _confirmDelete,
onRestore: _controller.isSubmitting ? null : _restoreMenu,
),
),
);
},
@@ -410,302 +402,283 @@ class _MenuEnabledPageState extends State<_MenuEnabledPage> {
final nameError = ValueNotifier<String?>(null);
final orderError = ValueNotifier<String?>(null);
await showDialog<bool>(
await SuperportDialog.show<bool>(
context: context,
builder: (dialogContext) {
final theme = ShadTheme.of(dialogContext);
final materialTheme = Theme.of(dialogContext);
final navigator = Navigator.of(dialogContext);
return Dialog(
insetPadding: const EdgeInsets.all(24),
clipBehavior: Clip.antiAlias,
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 560),
child: ShadCard(
title: Text(
isEdit ? '메뉴 수정' : '메뉴 등록',
style: theme.textTheme.h3,
),
description: Text(
'메뉴 정보를 ${isEdit ? '수정' : '입력'}하세요.',
style: theme.textTheme.muted,
),
footer: ValueListenableBuilder<bool>(
valueListenable: saving,
builder: (_, isSaving, __) {
return Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
ShadButton.ghost(
onPressed: isSaving ? null : () => navigator.pop(false),
child: const Text('취소'),
),
const SizedBox(width: 12),
ShadButton(
onPressed: isSaving
? null
: () async {
final code = codeController.text.trim();
final name = nameController.text.trim();
final path = pathController.text.trim();
final orderText = orderController.text.trim();
final note = noteController.text.trim();
dialog: SuperportDialog(
title: isEdit ? '메뉴 수정' : '메뉴 등록',
description: '메뉴 정보를 ${isEdit ? '수정' : '입력'}하세요.',
constraints: const BoxConstraints(maxWidth: 560),
secondaryAction: ValueListenableBuilder<bool>(
valueListenable: saving,
builder: (dialogContext, isSaving, __) {
return ShadButton.ghost(
onPressed: isSaving
? null
: () => Navigator.of(dialogContext).pop(false),
child: const Text('취소'),
);
},
),
primaryAction: ValueListenableBuilder<bool>(
valueListenable: saving,
builder: (dialogContext, isSaving, __) {
return ShadButton(
onPressed: isSaving
? null
: () async {
final code = codeController.text.trim();
final name = nameController.text.trim();
final path = pathController.text.trim();
final orderText = orderController.text.trim();
final note = noteController.text.trim();
codeError.value = code.isEmpty
? '메뉴코드를 입력하세요.'
: null;
nameError.value = name.isEmpty
? '메뉴명을 입력하세요.'
: null;
codeError.value = code.isEmpty ? '메뉴코드를 입력하세요.' : null;
nameError.value = name.isEmpty ? '메뉴명을 입력하세요.' : null;
int? orderValue;
if (orderText.isNotEmpty) {
orderValue = int.tryParse(orderText);
if (orderValue == null) {
orderError.value = '표시순서는 숫자여야 합니다.';
} else {
orderError.value = null;
}
} else {
orderError.value = null;
}
int? orderValue;
if (orderText.isNotEmpty) {
orderValue = int.tryParse(orderText);
orderError.value = orderValue == null
? '표시순서는 숫자여야 합니다.'
: null;
} else {
orderError.value = null;
}
if (codeError.value != null ||
nameError.value != null ||
orderError.value != null) {
return;
}
if (codeError.value != null ||
nameError.value != null ||
orderError.value != null) {
return;
}
saving.value = true;
final input = MenuInput(
menuCode: code,
menuName: name,
parentMenuId: parentNotifier.value,
path: path.isEmpty ? null : path,
displayOrder: orderValue,
isActive: isActiveNotifier.value,
note: note.isEmpty ? null : note,
);
final response = isEdit
? await _controller.update(menuId!, input)
: await _controller.create(input);
saving.value = false;
if (response != null) {
if (!navigator.mounted) {
return;
}
if (mounted) {
_showSnack(
isEdit ? '메뉴를 수정했습니다.' : '메뉴를 등록했습니다.',
);
}
navigator.pop(true);
saving.value = true;
final input = MenuInput(
menuCode: code,
menuName: name,
parentMenuId: parentNotifier.value,
path: path.isEmpty ? null : path,
displayOrder: orderValue,
isActive: isActiveNotifier.value,
note: note.isEmpty ? null : note,
);
final navigator = Navigator.of(dialogContext);
final response = isEdit
? await _controller.update(menuId!, input)
: await _controller.create(input);
saving.value = false;
if (response != null) {
if (!navigator.mounted) {
return;
}
if (mounted) {
_showSnack(isEdit ? '메뉴를 수정했습니다.' : '메뉴를 등록했습니다.');
}
navigator.pop(true);
}
},
child: Text(isEdit ? '저장' : '등록'),
);
},
),
child: ValueListenableBuilder<bool>(
valueListenable: saving,
builder: (dialogContext, isSaving, __) {
final theme = ShadTheme.of(dialogContext);
final materialTheme = Theme.of(dialogContext);
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;
}
},
child: Text(isEdit ? '저장' : '등록'),
),
],
);
},
),
child: SizedBox(
width: double.infinity,
child: 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,
),
),
),
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: parentNotifier,
builder: (_, value, __) {
return _FormField(
label: '상위메뉴',
child: ShadSelect<int?>(
initialValue: value,
placeholder: const Text('최상위'),
selectedOptionBuilder: (context, selected) {
if (selected == null) {
return const Text('최상위');
}
final target = _controller.parents.firstWhere(
(item) => item.id == selected,
orElse: () => MenuItem(
id: selected,
menuCode: '',
menuName: '',
),
);
final label = target.menuName.isEmpty
? '최상위'
: target.menuName;
return Text(label);
},
onChanged: saving.value
? null
: (next) => parentNotifier.value = next,
options: [
const ShadOption<int?>(
value: null,
child: Text('최상위'),
),
..._controller.parents
.where((item) => item.id != menuId)
.map(
(menuItem) => ShadOption<int?>(
value: menuItem.id,
child: Text(menuItem.menuName),
),
),
],
),
);
},
),
const SizedBox(height: 16),
_FormField(
label: '경로',
child: ShadInput(controller: pathController),
),
const SizedBox(height: 16),
ValueListenableBuilder<String?>(
valueListenable: orderError,
builder: (_, errorText, __) {
return _FormField(
label: '표시순서',
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ShadInput(
controller: orderController,
keyboardType: TextInputType.number,
),
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(existingMenu.createdAt)}',
style: theme.textTheme.small,
),
],
),
const SizedBox(height: 4),
Text(
'수정일시: ${_formatDateTime(existingMenu.updatedAt)}',
style: theme.textTheme.small,
),
],
],
);
},
),
),
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: parentNotifier,
builder: (_, value, __) {
return _FormField(
label: '상위메뉴',
child: ShadSelect<int?>(
initialValue: value,
placeholder: const Text('최상위'),
selectedOptionBuilder: (context, selected) {
if (selected == null) {
return const Text('최상위');
}
final target = _controller.parents.firstWhere(
(item) => item.id == selected,
orElse: () => MenuItem(
id: selected,
menuCode: '',
menuName: '',
),
);
final label = target.menuName.isEmpty
? '최상위'
: target.menuName;
return Text(label);
},
onChanged: isSaving
? null
: (next) => parentNotifier.value = next,
options: [
const ShadOption<int?>(
value: null,
child: Text('최상위'),
),
..._controller.parents
.where((item) => item.id != menuId)
.map(
(menuItem) => ShadOption<int?>(
value: menuItem.id,
child: Text(menuItem.menuName),
),
),
],
),
);
},
),
const SizedBox(height: 16),
_FormField(
label: '경로',
child: ShadInput(controller: pathController),
),
const SizedBox(height: 16),
ValueListenableBuilder<String?>(
valueListenable: orderError,
builder: (_, errorText, __) {
return _FormField(
label: '표시순서',
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
ShadInput(
controller: orderController,
keyboardType: TextInputType.number,
),
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: isSaving
? null
: (next) => isActiveNotifier.value = next,
),
const SizedBox(width: 8),
Text(value ? '사용' : '미사용'),
],
),
);
},
),
const SizedBox(height: 16),
_FormField(
label: '비고',
child: ShadTextarea(controller: noteController),
),
if (existingMenu != null) ...[
const SizedBox(height: 20),
Text(
'생성일시: ${_formatDateTime(existingMenu.createdAt)}',
style: theme.textTheme.small,
),
const SizedBox(height: 4),
Text(
'수정일시: ${_formatDateTime(existingMenu.updatedAt)}',
style: theme.textTheme.small,
),
],
],
),
),
),
);
},
);
},
),
),
);
codeController.dispose();
@@ -722,24 +695,28 @@ class _MenuEnabledPageState extends State<_MenuEnabledPage> {
}
Future<void> _confirmDelete(MenuItem menu) async {
final confirmed = await showDialog<bool>(
final confirmed = await SuperportDialog.show<bool>(
context: context,
builder: (dialogContext) {
return AlertDialog(
title: const Text('메뉴 삭제'),
content: Text('"${menu.menuName}" 메뉴를 삭제하시겠습니까?'),
actions: [
TextButton(
dialog: SuperportDialog(
title: '메뉴 삭제',
description: '"${menu.menuName}" 메뉴 삭제하시겠습니까?',
secondaryAction: Builder(
builder: (dialogContext) {
return ShadButton.ghost(
onPressed: () => Navigator.of(dialogContext).pop(false),
child: const Text('취소'),
),
TextButton(
);
},
),
primaryAction: Builder(
builder: (dialogContext) {
return ShadButton.destructive(
onPressed: () => Navigator.of(dialogContext).pop(true),
child: const Text('삭제'),
),
],
);
},
);
},
),
),
);
if (confirmed == true && menu.id != null) {

View File

@@ -11,6 +11,8 @@ import '../../domain/repositories/product_repository.dart';
enum ProductStatusFilter { all, activeOnly, inactiveOnly }
class ProductController extends ChangeNotifier {
static const int defaultPageSize = 20;
ProductController({
required ProductRepository productRepository,
required VendorRepository vendorRepository,
@@ -31,6 +33,7 @@ class ProductController extends ChangeNotifier {
int? _vendorFilter;
int? _uomFilter;
ProductStatusFilter _statusFilter = ProductStatusFilter.all;
int _pageSize = defaultPageSize;
String? _errorMessage;
List<Vendor> _vendorOptions = const [];
@@ -44,6 +47,7 @@ class ProductController extends ChangeNotifier {
int? get vendorFilter => _vendorFilter;
int? get uomFilter => _uomFilter;
ProductStatusFilter get statusFilter => _statusFilter;
int get pageSize => _pageSize;
String? get errorMessage => _errorMessage;
List<Vendor> get vendorOptions => _vendorOptions;
List<Uom> get uomOptions => _uomOptions;
@@ -60,13 +64,16 @@ class ProductController extends ChangeNotifier {
};
final response = await _productRepository.list(
page: page,
pageSize: _result?.pageSize ?? 20,
pageSize: _pageSize,
query: _query.isEmpty ? null : _query,
vendorId: _vendorFilter,
uomId: _uomFilter,
isActive: isActive,
);
_result = response;
if (response.pageSize > 0 && response.pageSize != _pageSize) {
_pageSize = response.pageSize;
}
} catch (e) {
_errorMessage = e.toString();
} finally {
@@ -92,25 +99,45 @@ class ProductController extends ChangeNotifier {
}
void updateQuery(String value) {
if (_query == value) {
return;
}
_query = value;
notifyListeners();
}
void updateVendorFilter(int? vendorId) {
if (_vendorFilter == vendorId) {
return;
}
_vendorFilter = vendorId;
notifyListeners();
}
void updateUomFilter(int? uomId) {
if (_uomFilter == uomId) {
return;
}
_uomFilter = uomId;
notifyListeners();
}
void updateStatusFilter(ProductStatusFilter filter) {
if (_statusFilter == filter) {
return;
}
_statusFilter = filter;
notifyListeners();
}
void updatePageSize(int size) {
if (size <= 0 || _pageSize == size) {
return;
}
_pageSize = size;
notifyListeners();
}
Future<Product?> create(ProductInput input) async {
_setSubmitting(true);
try {

View File

@@ -11,6 +11,8 @@ enum VendorStatusFilter { all, activeOnly, inactiveOnly }
/// - 목록/검색/필터/페이지 상태를 관리한다.
/// - 생성/수정/삭제/복구 요청을 래핑하여 UI에 알린다.
class VendorController extends ChangeNotifier {
static const int defaultPageSize = 20;
VendorController({required VendorRepository repository})
: _repository = repository;
@@ -21,6 +23,7 @@ class VendorController extends ChangeNotifier {
bool _isSubmitting = false;
String _query = '';
VendorStatusFilter _statusFilter = VendorStatusFilter.all;
int _pageSize = defaultPageSize;
String? _errorMessage;
PaginatedResult<Vendor>? get result => _result;
@@ -28,6 +31,7 @@ class VendorController extends ChangeNotifier {
bool get isSubmitting => _isSubmitting;
String get query => _query;
VendorStatusFilter get statusFilter => _statusFilter;
int get pageSize => _pageSize;
String? get errorMessage => _errorMessage;
/// 목록 갱신
@@ -43,11 +47,14 @@ class VendorController extends ChangeNotifier {
};
final response = await _repository.list(
page: page,
pageSize: _result?.pageSize ?? 20,
pageSize: _pageSize,
query: _query.isEmpty ? null : _query,
isActive: isActive,
);
_result = response;
if (response.pageSize > 0 && response.pageSize != _pageSize) {
_pageSize = response.pageSize;
}
} catch (e) {
_errorMessage = e.toString();
} finally {
@@ -57,15 +64,29 @@ class VendorController extends ChangeNotifier {
}
void updateQuery(String value) {
if (_query == value) {
return;
}
_query = value;
notifyListeners();
}
void updateStatusFilter(VendorStatusFilter filter) {
if (_statusFilter == filter) {
return;
}
_statusFilter = filter;
notifyListeners();
}
void updatePageSize(int size) {
if (size <= 0 || _pageSize == size) {
return;
}
_pageSize = size;
notifyListeners();
}
/// 신규 등록
Future<Vendor?> create(VendorInput input) async {
_setSubmitting(true);

View File

@@ -1,10 +1,13 @@
import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
import 'package:go_router/go_router.dart';
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_table.dart';
import '../../../../../core/config/environment.dart';
import '../../../../../widgets/spec_page.dart';
@@ -13,7 +16,9 @@ import '../../../vendor/domain/repositories/vendor_repository.dart';
import '../controllers/vendor_controller.dart';
class VendorPage extends StatelessWidget {
const VendorPage({super.key});
const VendorPage({super.key, required this.routeUri});
final Uri routeUri;
@override
Widget build(BuildContext context) {
@@ -58,12 +63,14 @@ class VendorPage extends StatelessWidget {
);
}
return const _VendorEnabledPage();
return _VendorEnabledPage(routeUri: routeUri);
}
}
class _VendorEnabledPage extends StatefulWidget {
const _VendorEnabledPage();
const _VendorEnabledPage({required this.routeUri});
final Uri routeUri;
@override
State<_VendorEnabledPage> createState() => _VendorEnabledPageState();
@@ -75,13 +82,22 @@ class _VendorEnabledPageState extends State<_VendorEnabledPage> {
final FocusNode _searchFocusNode = FocusNode();
final DateFormat _dateFormat = DateFormat('yyyy-MM-dd HH:mm');
String? _lastError;
bool _routeApplied = false;
@override
void initState() {
super.initState();
_controller = VendorController(repository: GetIt.I<VendorRepository>());
_controller.addListener(_onControllerChanged);
WidgetsBinding.instance.addPostFrameCallback((_) => _controller.fetch());
_controller = VendorController(repository: GetIt.I<VendorRepository>())
..addListener(_onControllerChanged);
}
@override
void didChangeDependencies() {
super.didChangeDependencies();
if (!_routeApplied) {
_routeApplied = true;
_applyRouteParameters();
}
}
@override
@@ -140,6 +156,32 @@ class _VendorEnabledPageState extends State<_VendorEnabledPage> {
),
],
toolbar: FilterBar(
actions: [
ShadButton.outline(
onPressed: _controller.isLoading ? null : _applyFilters,
child: const Text('검색 적용'),
),
if (_searchController.text.isNotEmpty ||
_controller.statusFilter != VendorStatusFilter.all)
ShadButton.ghost(
onPressed: _controller.isLoading
? null
: () {
_searchController.clear();
_searchFocusNode.requestFocus();
_controller.updateQuery('');
_controller.updateStatusFilter(
VendorStatusFilter.all,
);
_updateRoute(
page: 1,
queryOverride: '',
statusOverride: VendorStatusFilter.all,
);
},
child: const Text('초기화'),
),
],
children: [
SizedBox(
width: 280,
@@ -159,10 +201,9 @@ class _VendorEnabledPageState extends State<_VendorEnabledPage> {
selectedOptionBuilder: (context, value) =>
Text(_statusLabel(value)),
onChanged: (value) {
if (value != null) {
_controller.updateStatusFilter(value);
_controller.fetch(page: 1);
}
if (value == null) return;
_controller.updateStatusFilter(value);
_updateRoute(page: 1, statusOverride: value);
},
options: VendorStatusFilter.values
.map(
@@ -174,26 +215,6 @@ class _VendorEnabledPageState extends State<_VendorEnabledPage> {
.toList(),
),
),
ShadButton.outline(
onPressed: _controller.isLoading ? null : _applyFilters,
child: const Text('검색 적용'),
),
if (_searchController.text.isNotEmpty ||
_controller.statusFilter != VendorStatusFilter.all)
ShadButton.ghost(
onPressed: _controller.isLoading
? null
: () {
_searchController.clear();
_searchFocusNode.requestFocus();
_controller.updateQuery('');
_controller.updateStatusFilter(
VendorStatusFilter.all,
);
_controller.fetch(page: 1);
},
child: const Text('초기화'),
),
],
),
child: ShadCard(
@@ -217,7 +238,7 @@ class _VendorEnabledPageState extends State<_VendorEnabledPage> {
size: ShadButtonSize.sm,
onPressed: _controller.isLoading || currentPage <= 1
? null
: () => _controller.fetch(page: currentPage - 1),
: () => _goToPage(currentPage - 1),
child: const Text('이전'),
),
const SizedBox(width: 8),
@@ -225,7 +246,7 @@ class _VendorEnabledPageState extends State<_VendorEnabledPage> {
size: ShadButtonSize.sm,
onPressed: _controller.isLoading || !hasNext
? null
: () => _controller.fetch(page: currentPage + 1),
: () => _goToPage(currentPage + 1),
child: const Text('다음'),
),
],
@@ -238,27 +259,22 @@ class _VendorEnabledPageState extends State<_VendorEnabledPage> {
child: Center(child: CircularProgressIndicator()),
)
: vendors.isEmpty
? Padding(
padding: const EdgeInsets.all(32),
child: Text(
'조건에 맞는 벤더가 없습니다.',
style: theme.textTheme.muted,
),
)
: _VendorTable(
vendors: vendors,
onEdit: _controller.isSubmitting
? null
: (vendor) =>
_openVendorForm(context, vendor: vendor),
onDelete: _controller.isSubmitting
? null
: _confirmDelete,
onRestore: _controller.isSubmitting
? null
: _restoreVendor,
dateFormat: _dateFormat,
),
? Padding(
padding: const EdgeInsets.all(32),
child: Text(
'조건에 맞는 벤더가 없습니다.',
style: theme.textTheme.muted,
),
)
: _VendorTable(
vendors: vendors,
onEdit: _controller.isSubmitting
? null
: (vendor) => _openVendorForm(context, vendor: vendor),
onDelete: _controller.isSubmitting ? null : _confirmDelete,
onRestore: _controller.isSubmitting ? null : _restoreVendor,
dateFormat: _dateFormat,
),
),
);
},
@@ -266,8 +282,9 @@ class _VendorEnabledPageState extends State<_VendorEnabledPage> {
}
void _applyFilters() {
_controller.updateQuery(_searchController.text.trim());
_controller.fetch(page: 1);
final keyword = _searchController.text.trim();
_controller.updateQuery(keyword);
_updateRoute(page: 1, queryOverride: keyword);
}
String _statusLabel(VendorStatusFilter filter) {
@@ -281,6 +298,90 @@ class _VendorEnabledPageState extends State<_VendorEnabledPage> {
}
}
void _applyRouteParameters() {
final params = widget.routeUri.queryParameters;
final query = params['q'] ?? '';
final status = _statusFromParam(params['status']);
final pageSizeParam = int.tryParse(params['page_size'] ?? '');
final pageParam = int.tryParse(params['page'] ?? '');
_searchController.text = query;
_controller.updateQuery(query);
_controller.updateStatusFilter(status);
if (pageSizeParam != null && pageSizeParam > 0) {
_controller.updatePageSize(pageSizeParam);
}
final page = pageParam != null && pageParam > 0 ? pageParam : 1;
_controller.fetch(page: page);
}
void _goToPage(int page) {
if (page < 1) {
page = 1;
}
_updateRoute(page: page);
}
void _updateRoute({
required int page,
String? queryOverride,
VendorStatusFilter? statusOverride,
int? pageSizeOverride,
}) {
final query = queryOverride ?? _controller.query;
final status = statusOverride ?? _controller.statusFilter;
final pageSize = pageSizeOverride ?? _controller.pageSize;
final params = <String, String>{};
if (query.isNotEmpty) {
params['q'] = query;
}
final statusParam = _encodeStatus(status);
if (statusParam != null) {
params['status'] = statusParam;
}
if (page > 1) {
params['page'] = page.toString();
}
if (pageSize > 0 && pageSize != VendorController.defaultPageSize) {
params['page_size'] = pageSize.toString();
}
final uri = Uri(
path: widget.routeUri.path,
queryParameters: params.isEmpty ? null : params,
);
final newLocation = uri.toString();
if (widget.routeUri.toString() == newLocation) {
_controller.fetch(page: page);
return;
}
GoRouter.of(context).go(newLocation);
}
VendorStatusFilter _statusFromParam(String? value) {
switch (value) {
case 'active':
return VendorStatusFilter.activeOnly;
case 'inactive':
return VendorStatusFilter.inactiveOnly;
default:
return VendorStatusFilter.all;
}
}
String? _encodeStatus(VendorStatusFilter filter) {
switch (filter) {
case VendorStatusFilter.all:
return null;
case VendorStatusFilter.activeOnly:
return 'active';
case VendorStatusFilter.inactiveOnly:
return 'inactive';
}
}
Future<void> _openVendorForm(BuildContext context, {Vendor? vendor}) async {
final existingVendor = vendor;
final isEdit = existingVendor != null;
@@ -306,201 +407,183 @@ class _VendorEnabledPageState extends State<_VendorEnabledPage> {
final codeError = ValueNotifier<String?>(null);
final nameError = ValueNotifier<String?>(null);
await showDialog<bool>(
await SuperportDialog.show<bool>(
context: context,
builder: (dialogContext) {
final theme = ShadTheme.of(dialogContext);
final materialTheme = Theme.of(dialogContext);
final navigator = Navigator.of(dialogContext);
return Dialog(
insetPadding: const EdgeInsets.all(24),
clipBehavior: Clip.antiAlias,
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 520),
child: ShadCard(
title: Text(
isEdit ? '벤더 수정' : '벤더 등록',
style: theme.textTheme.h3,
),
description: Text(
'벤더 기본 정보를 ${isEdit ? '수정' : '입력'}하세요.',
style: theme.textTheme.muted,
),
footer: ValueListenableBuilder<bool>(
valueListenable: saving,
builder: (_, isSaving, __) {
return Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
ShadButton.ghost(
onPressed: isSaving ? null : () => navigator.pop(false),
child: const Text('취소'),
),
const SizedBox(width: 12),
ShadButton(
onPressed: isSaving
? null
: () async {
final code = codeController.text.trim();
final name = nameController.text.trim();
final note = noteController.text.trim();
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;
codeError.value = code.isEmpty ? '벤더코드를 입력하세요.' : null;
nameError.value = name.isEmpty ? '벤더명을 입력하세요.' : null;
if (codeError.value != null ||
nameError.value != null) {
return;
}
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 response = isEdit
? await _controller.update(vendorId!, input)
: await _controller.create(input);
saving.value = false;
if (response != null) {
if (!navigator.mounted) {
return;
}
if (mounted) {
_showSnack(
isEdit ? '벤더를 수정했습니다.' : '벤더를 등록했습니다.',
);
}
navigator.pop(true);
saving.value = true;
final input = VendorInput(
vendorCode: code,
vendorName: name,
isActive: isActiveNotifier.value,
note: note.isEmpty ? null : note,
);
final navigator = Navigator.of(context);
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).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;
}
},
child: Text(isEdit ? '저장' : '등록'),
),
],
);
},
),
child: 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,
),
),
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: 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),
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: 16),
_FormField(
label: '비고',
child: ShadTextarea(controller: noteController),
const SizedBox(height: 4),
Text(
'수정일시: ${_formatDateTime(existingVendor.updatedAt)}',
style: theme.textTheme.small,
),
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,
),
],
],
),
],
),
),
),
);
},
);
},
),
),
);
codeController.dispose();
@@ -513,24 +596,22 @@ class _VendorEnabledPageState extends State<_VendorEnabledPage> {
}
Future<void> _confirmDelete(Vendor vendor) async {
final confirmed = await showDialog<bool>(
final confirmed = await SuperportDialog.show<bool>(
context: context,
builder: (dialogContext) {
return AlertDialog(
title: const Text('벤더 삭제'),
content: Text('"${vendor.vendorName}" 벤더를 삭제하시겠습니까?'),
actions: [
TextButton(
onPressed: () => Navigator.of(dialogContext).pop(false),
child: const Text('취소'),
),
TextButton(
onPressed: () => Navigator.of(dialogContext).pop(true),
child: const Text('삭제'),
),
],
);
},
dialog: SuperportDialog(
title: '벤더 삭제',
description: '"${vendor.vendorName}" 벤더 삭제하시겠습니까?',
actions: [
ShadButton.ghost(
onPressed: () => Navigator.of(context).pop(false),
child: const Text('취소'),
),
ShadButton(
onPressed: () => Navigator.of(context).pop(true),
child: const Text('삭제'),
),
],
),
);
if (confirmed == true && vendor.id != null) {
@@ -581,39 +662,43 @@ class _VendorTable extends StatelessWidget {
@override
Widget build(BuildContext context) {
final header = [
'ID',
'벤더코드',
'벤더명',
'사용',
'삭제',
'비고',
'변경일시',
'동작',
].map((text) => ShadTableCell.header(child: Text(text))).toList();
final columns = const [
Text('ID'),
Text('벤더코드'),
Text('벤더명'),
Text('사용'),
Text('삭제'),
Text('비고'),
Text('변경일시'),
Text('동작'),
];
final rows = vendors.map((vendor) {
return [
vendor.id?.toString() ?? '-',
vendor.vendorCode,
vendor.vendorName,
vendor.isActive ? 'Y' : 'N',
vendor.isDeleted ? 'Y' : '-',
vendor.note?.isEmpty ?? true ? '-' : vendor.note!,
vendor.updatedAt == null
? '-'
: dateFormat.format(vendor.updatedAt!.toLocal()),
].map((text) => ShadTableCell(child: Text(text))).toList()..add(
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(
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
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),
),
const SizedBox(width: 8),
vendor.isDeleted
? ShadButton.ghost(
size: ShadButtonSize.sm,
@@ -633,17 +718,18 @@ class _VendorTable extends StatelessWidget {
),
),
);
return cells;
}).toList();
return SizedBox(
height: 56.0 * (vendors.length + 1),
child: ShadTable.list(
header: header,
children: rows,
columnSpanExtent: (index) => index == 7
? const FixedTableSpanExtent(160)
: const FixedTableSpanExtent(140),
),
return SuperportTable(
columns: columns,
rows: rows,
rowHeight: 56,
maxHeight: 520,
columnSpanExtent: (index) => index == 7
? const FixedTableSpanExtent(160)
: const FixedTableSpanExtent(140),
);
}
}

View File

@@ -7,6 +7,8 @@ import '../../domain/repositories/warehouse_repository.dart';
enum WarehouseStatusFilter { all, activeOnly, inactiveOnly }
class WarehouseController extends ChangeNotifier {
static const int defaultPageSize = 20;
WarehouseController({required WarehouseRepository repository})
: _repository = repository;
@@ -17,6 +19,7 @@ class WarehouseController extends ChangeNotifier {
bool _isSubmitting = false;
String _query = '';
WarehouseStatusFilter _statusFilter = WarehouseStatusFilter.all;
int _pageSize = defaultPageSize;
String? _errorMessage;
PaginatedResult<Warehouse>? get result => _result;
@@ -24,6 +27,7 @@ class WarehouseController extends ChangeNotifier {
bool get isSubmitting => _isSubmitting;
String get query => _query;
WarehouseStatusFilter get statusFilter => _statusFilter;
int get pageSize => _pageSize;
String? get errorMessage => _errorMessage;
Future<void> fetch({int page = 1}) async {
@@ -38,11 +42,14 @@ class WarehouseController extends ChangeNotifier {
};
final response = await _repository.list(
page: page,
pageSize: _result?.pageSize ?? 20,
pageSize: _pageSize,
query: _query.isEmpty ? null : _query,
isActive: isActive,
);
_result = response;
if (response.pageSize > 0 && response.pageSize != _pageSize) {
_pageSize = response.pageSize;
}
} catch (e) {
_errorMessage = e.toString();
} finally {
@@ -52,15 +59,29 @@ class WarehouseController extends ChangeNotifier {
}
void updateQuery(String value) {
if (_query == value) {
return;
}
_query = value;
notifyListeners();
}
void updateStatusFilter(WarehouseStatusFilter filter) {
if (_statusFilter == filter) {
return;
}
_statusFilter = filter;
notifyListeners();
}
void updatePageSize(int size) {
if (size <= 0 || _pageSize == size) {
return;
}
_pageSize = size;
notifyListeners();
}
Future<Warehouse?> create(WarehouseInput input) async {
_setSubmitting(true);
try {