결재 템플릿 단계 적용 구현

- ApprovalTemplate 엔티티·DTO·원격 리포지토리 추가
- ApprovalController에 템플릿 로딩/적용 상태와 assignSteps 호출 연동
- ApprovalPage 단계 탭에 템플릿 선택 UI 및 적용 확인 다이얼로그 구현
- 템플릿 적용 단위 테스트와 IMPLEMENTATION_TASKS 현황 갱신
This commit is contained in:
JiWoong Sul
2025-09-25 00:21:12 +09:00
parent b6e50464d2
commit c3010965ad
63 changed files with 10179 additions and 1436 deletions

View File

@@ -0,0 +1,179 @@
import 'package:flutter/foundation.dart';
import 'package:superport_v2/core/common/models/paginated_result.dart';
import '../../domain/entities/menu.dart';
import '../../domain/repositories/menu_repository.dart';
enum MenuStatusFilter { all, activeOnly, inactiveOnly }
/// 메뉴 마스터 상태 컨트롤러
///
/// - 목록, 필터, 페이지 상태를 관리한다.
/// - CRUD 및 복구 요청을 처리한다.
class MenuController extends ChangeNotifier {
MenuController({required MenuRepository repository})
: _repository = repository;
final MenuRepository _repository;
PaginatedResult<MenuItem>? _result;
bool _isLoading = false;
bool _isSubmitting = false;
bool _isLoadingParents = false;
String _query = '';
int? _parentFilter;
MenuStatusFilter _statusFilter = MenuStatusFilter.all;
bool _includeDeleted = false;
String? _errorMessage;
List<MenuItem> _parents = const [];
PaginatedResult<MenuItem>? get result => _result;
bool get isLoading => _isLoading;
bool get isSubmitting => _isSubmitting;
bool get isLoadingParents => _isLoadingParents;
String get query => _query;
int? get parentFilter => _parentFilter;
MenuStatusFilter get statusFilter => _statusFilter;
bool get includeDeleted => _includeDeleted;
String? get errorMessage => _errorMessage;
List<MenuItem> get parents => _parents;
Future<void> loadParents() async {
_isLoadingParents = true;
notifyListeners();
try {
final response = await _repository.list(
page: 1,
pageSize: 200,
includeDeleted: false,
);
_parents = response.items;
} catch (e) {
_errorMessage = e.toString();
} finally {
_isLoadingParents = false;
notifyListeners();
}
}
Future<void> fetch({int page = 1}) async {
_isLoading = true;
_errorMessage = null;
notifyListeners();
try {
final isActive = switch (_statusFilter) {
MenuStatusFilter.all => null,
MenuStatusFilter.activeOnly => true,
MenuStatusFilter.inactiveOnly => false,
};
final response = await _repository.list(
page: page,
pageSize: _result?.pageSize ?? 20,
query: _query.isEmpty ? null : _query,
parentId: _parentFilter,
isActive: isActive,
includeDeleted: _includeDeleted,
);
_result = response;
} catch (e) {
_errorMessage = e.toString();
} finally {
_isLoading = false;
notifyListeners();
}
}
void updateQuery(String value) {
_query = value;
notifyListeners();
}
void updateParentFilter(int? parentId) {
_parentFilter = parentId;
notifyListeners();
}
void updateStatusFilter(MenuStatusFilter filter) {
_statusFilter = filter;
notifyListeners();
}
void updateIncludeDeleted(bool value) {
_includeDeleted = value;
notifyListeners();
}
Future<MenuItem?> create(MenuInput input) async {
_setSubmitting(true);
try {
final created = await _repository.create(input);
await fetch(page: 1);
await loadParents();
return created;
} catch (e) {
_errorMessage = e.toString();
notifyListeners();
return null;
} finally {
_setSubmitting(false);
}
}
Future<MenuItem?> update(int id, MenuInput input) async {
_setSubmitting(true);
try {
final updated = await _repository.update(id, input);
await fetch(page: _result?.page ?? 1);
await loadParents();
return updated;
} catch (e) {
_errorMessage = e.toString();
notifyListeners();
return null;
} finally {
_setSubmitting(false);
}
}
Future<bool> delete(int id) async {
_setSubmitting(true);
try {
await _repository.delete(id);
await fetch(page: _result?.page ?? 1);
await loadParents();
return true;
} catch (e) {
_errorMessage = e.toString();
notifyListeners();
return false;
} finally {
_setSubmitting(false);
}
}
Future<MenuItem?> restore(int id) async {
_setSubmitting(true);
try {
final restored = await _repository.restore(id);
await fetch(page: _result?.page ?? 1);
await loadParents();
return restored;
} catch (e) {
_errorMessage = e.toString();
notifyListeners();
return null;
} finally {
_setSubmitting(false);
}
}
void clearError() {
_errorMessage = null;
notifyListeners();
}
void _setSubmitting(bool value) {
_isSubmitting = value;
notifyListeners();
}
}

View File

@@ -1,51 +1,893 @@
import 'package:flutter/widgets.dart';
import 'package:flutter/material.dart';
import 'package:get_it/get_it.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 '../../../../../core/config/environment.dart';
import '../../../../../widgets/spec_page.dart';
import '../../domain/entities/menu.dart';
import '../../domain/repositories/menu_repository.dart';
import '../controllers/menu_controller.dart' as menu;
class MenuPage extends StatelessWidget {
const MenuPage({super.key});
@override
Widget build(BuildContext context) {
return const SpecPage(
title: '메뉴 관리',
summary: '메뉴 계층, 경로, 노출 순서를 구성합니다.',
sections: [
SpecSection(
title: '입력 폼',
items: [
'메뉴코드 [Text]',
'메뉴명 [Text]',
'상위메뉴 [Dropdown]',
'경로 [Text]',
'표시순서 [Number]',
'사용여부 [Switch]',
'비고 [Text]',
],
),
SpecSection(
title: '수정 폼',
items: ['메뉴코드 [ReadOnly]', '생성일시 [ReadOnly]'],
),
SpecSection(
title: '테이블 리스트',
description: '1행 예시',
table: SpecTable(
columns: ['번호', '메뉴코드', '메뉴명', '상위메뉴', '경로', '사용여부', '비고', '변경일시'],
rows: [
[
'1',
'MN-001',
'대시보드',
'-',
'/dashboard',
'Y',
'-',
'2024-03-01 10:00',
final enabled = Environment.flag('FEATURE_MENUS_ENABLED');
if (!enabled) {
return SpecPage(
title: '메뉴 관리',
summary: '메뉴 코드, 트리 구조, 사용여부를 관리합니다.',
trailing: ShadBadge(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 6),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(LucideIcons.info, size: 14),
const SizedBox(width: 6),
const Text('비활성화 (백엔드 준비 중)'),
],
),
),
),
sections: const [
SpecSection(
title: '입력 폼',
items: [
'메뉴코드 [Text]',
'메뉴명 [Text]',
'상위메뉴 [Dropdown]',
'경로 [Text]',
'표시순서 [Number]',
'사용여부 [Switch]',
'비고 [Text]',
],
),
SpecSection(
title: '수정 폼',
items: ['메뉴코드 [ReadOnly]', '생성일시 [ReadOnly]'],
),
SpecSection(
title: '테이블 리스트',
description: '1행 예시',
table: SpecTable(
columns: [
'번호',
'메뉴코드',
'메뉴명',
'상위메뉴',
'경로',
'사용여부',
'비고',
'변경일시',
],
rows: [
[
'1',
'MENU001',
'대시보드',
'-',
'/dashboard',
'Y',
'-',
'2024-03-01 10:00',
],
],
),
),
],
);
}
return const _MenuEnabledPage();
}
}
class _MenuEnabledPage extends StatefulWidget {
const _MenuEnabledPage();
@override
State<_MenuEnabledPage> createState() => _MenuEnabledPageState();
}
class _MenuEnabledPageState extends State<_MenuEnabledPage> {
late final menu.MenuController _controller;
final TextEditingController _searchController = TextEditingController();
final FocusNode _searchFocus = FocusNode();
final DateFormat _dateFormat = DateFormat('yyyy-MM-dd HH:mm');
String? _lastError;
@override
void initState() {
super.initState();
_controller = menu.MenuController(repository: GetIt.I<MenuRepository>())
..addListener(_handleControllerUpdate);
WidgetsBinding.instance.addPostFrameCallback((_) async {
await _controller.loadParents();
await _controller.fetch();
});
}
void _handleControllerUpdate() {
final error = _controller.errorMessage;
if (error != null && error != _lastError && mounted) {
_lastError = error;
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text(error)));
_controller.clearError();
}
}
@override
void dispose() {
_controller.removeListener(_handleControllerUpdate);
_controller.dispose();
_searchController.dispose();
_searchFocus.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
final theme = ShadTheme.of(context);
return AnimatedBuilder(
animation: _controller,
builder: (context, _) {
final result = _controller.result;
final menus = result?.items ?? const <MenuItem>[];
final totalCount = result?.total ?? 0;
final currentPage = result?.page ?? 1;
final totalPages = result == null || result.pageSize == 0
? 1
: (result.total / result.pageSize).ceil().clamp(1, 9999);
final hasNext = result == null
? false
: (result.page * result.pageSize) < result.total;
final showReset = _searchController.text.isNotEmpty ||
_controller.parentFilter != null ||
_controller.statusFilter != menu.MenuStatusFilter.all ||
_controller.includeDeleted;
return AppLayout(
title: '메뉴 관리',
subtitle: '메뉴 트리와 경로, 사용 상태를 관리합니다.',
breadcrumbs: const [
AppBreadcrumbItem(label: '대시보드', path: dashboardRoutePath),
AppBreadcrumbItem(label: '마스터', path: '/masters/menus'),
AppBreadcrumbItem(label: '메뉴'),
],
actions: [
ShadButton(
leading: const Icon(LucideIcons.plus, size: 16),
onPressed:
_controller.isSubmitting ? null : () => _openMenuForm(context),
child: const Text('신규 등록'),
),
],
toolbar: FilterBar(
children: [
SizedBox(
width: 260,
child: ShadInput(
controller: _searchController,
focusNode: _searchFocus,
placeholder: const Text('메뉴코드, 메뉴명 검색'),
leading: const Icon(LucideIcons.search, size: 16),
onSubmitted: (_) => _applyFilters(),
),
),
SizedBox(
width: 220,
child: ShadSelect<int?>(
key: ValueKey(_controller.parentFilter),
initialValue: _controller.parentFilter,
placeholder: Text(
_controller.isLoadingParents ? '상위 로딩중...' : '상위 전체',
),
selectedOptionBuilder: (context, value) {
if (value == null) {
return Text(
_controller.isLoadingParents
? '상위 로딩중...'
: '상위 전체',
);
}
final target = _controller.parents.firstWhere(
(menuItem) => menuItem.id == value,
orElse: () => MenuItem(
id: value,
menuCode: '',
menuName: '',
),
);
final label = target.menuName.isEmpty
? '상위 전체'
: target.menuName;
return Text(label);
},
onChanged: _controller.isLoadingParents
? null
: (value) {
_controller.updateParentFilter(value);
_controller.fetch(page: 1);
},
options: [
const ShadOption<int?>(
value: null,
child: Text('상위 전체'),
),
..._controller.parents.map(
(menuItem) => ShadOption<int?>(
value: menuItem.id,
child: Text(menuItem.menuName),
),
),
],
),
),
SizedBox(
width: 200,
child: ShadSelect<menu.MenuStatusFilter>(
key: ValueKey(_controller.statusFilter),
initialValue: _controller.statusFilter,
selectedOptionBuilder: (context, filter) =>
Text(_statusLabel(filter)),
onChanged: (value) {
if (value == null) return;
_controller.updateStatusFilter(value);
_controller.fetch(page: 1);
},
options: menu.MenuStatusFilter.values
.map(
(filter) => ShadOption(
value: filter,
child: Text(_statusLabel(filter)),
),
)
.toList(),
),
),
Row(
mainAxisSize: MainAxisSize.min,
children: [
ShadSwitch(
value: _controller.includeDeleted,
onChanged: (value) {
_controller.updateIncludeDeleted(value);
_controller.fetch(page: 1);
},
),
const SizedBox(width: 8),
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(
title: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('메뉴 목록', style: theme.textTheme.h3),
Text('$totalCount건', style: theme.textTheme.muted),
],
),
footer: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'페이지 $currentPage / $totalPages',
style: theme.textTheme.small,
),
Row(
children: [
ShadButton.outline(
size: ShadButtonSize.sm,
onPressed: _controller.isLoading || currentPage <= 1
? null
: () => _controller.fetch(page: currentPage - 1),
child: const Text('이전'),
),
const SizedBox(width: 8),
ShadButton.outline(
size: ShadButtonSize.sm,
onPressed: _controller.isLoading || !hasNext
? null
: () => _controller.fetch(page: currentPage + 1),
child: const Text('다음'),
),
],
),
],
),
child: _controller.isLoading
? const Padding(
padding: EdgeInsets.all(48),
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,
),
),
);
},
);
}
void _applyFilters() {
_controller.updateQuery(_searchController.text.trim());
_controller.fetch(page: 1);
}
String _statusLabel(menu.MenuStatusFilter filter) {
switch (filter) {
case menu.MenuStatusFilter.all:
return '전체(사용/미사용)';
case menu.MenuStatusFilter.activeOnly:
return '사용중';
case menu.MenuStatusFilter.inactiveOnly:
return '미사용';
}
}
Future<void> _openMenuForm(BuildContext context, {MenuItem? menu}) async {
final existingMenu = menu;
final isEdit = existingMenu != null;
final menuId = existingMenu?.id;
if (isEdit && menuId == null) {
_showSnack('ID 정보가 없어 수정할 수 없습니다.');
return;
}
final codeController = TextEditingController(
text: existingMenu?.menuCode ?? '',
);
final nameController = TextEditingController(
text: existingMenu?.menuName ?? '',
);
final pathController = TextEditingController(
text: existingMenu?.path ?? '',
);
final orderController = TextEditingController(
text: existingMenu?.displayOrder?.toString() ?? '',
);
final noteController = TextEditingController(
text: existingMenu?.note ?? '',
);
final parentNotifier = ValueNotifier<int?>(existingMenu?.parent?.id);
final isActiveNotifier = ValueNotifier<bool>(
existingMenu?.isActive ?? true,
);
final saving = ValueNotifier<bool>(false);
final codeError = ValueNotifier<String?>(null);
final nameError = ValueNotifier<String?>(null);
final orderError = ValueNotifier<String?>(null);
await showDialog<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();
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;
}
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);
}
},
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,
),
),
),
],
),
);
},
),
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,
),
],
],
),
),
),
),
),
);
},
);
codeController.dispose();
nameController.dispose();
pathController.dispose();
orderController.dispose();
noteController.dispose();
parentNotifier.dispose();
isActiveNotifier.dispose();
saving.dispose();
codeError.dispose();
nameError.dispose();
orderError.dispose();
}
Future<void> _confirmDelete(MenuItem menu) async {
final confirmed = await showDialog<bool>(
context: context,
builder: (dialogContext) {
return AlertDialog(
title: const Text('메뉴 삭제'),
content: Text('"${menu.menuName}" 메뉴를 삭제하시겠습니까?'),
actions: [
TextButton(
onPressed: () => Navigator.of(dialogContext).pop(false),
child: const Text('취소'),
),
TextButton(
onPressed: () => Navigator.of(dialogContext).pop(true),
child: const Text('삭제'),
),
],
);
},
);
if (confirmed == true && menu.id != null) {
final success = await _controller.delete(menu.id!);
if (success && mounted) {
_showSnack('메뉴를 삭제했습니다.');
}
}
}
Future<void> _restoreMenu(MenuItem menu) async {
if (menu.id == null) return;
final restored = await _controller.restore(menu.id!);
if (restored != null && mounted) {
_showSnack('메뉴를 복구했습니다.');
}
}
void _showSnack(String message) {
if (!mounted) return;
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text(message)));
}
String _formatDateTime(DateTime? value) {
if (value == null) {
return '-';
}
return _dateFormat.format(value.toLocal());
}
}
class _MenuTable extends StatelessWidget {
const _MenuTable({
required this.menus,
required this.onEdit,
required this.onDelete,
required this.onRestore,
required this.dateFormat,
});
final List<MenuItem> menus;
final void Function(MenuItem menu)? onEdit;
final void Function(MenuItem menu)? onDelete;
final void Function(MenuItem menu)? onRestore;
final DateFormat dateFormat;
@override
Widget build(BuildContext context) {
final header = [
'ID',
'메뉴코드',
'메뉴명',
'상위메뉴',
'경로',
'사용',
'삭제',
'비고',
'변경일시',
'동작',
].map((text) => ShadTableCell.header(child: Text(text))).toList();
final rows = menus.map((item) {
final cells = [
item.id?.toString() ?? '-',
item.menuCode,
item.menuName,
item.parent?.menuName ?? '-',
item.path?.isEmpty ?? true ? '-' : item.path!,
item.isActive ? 'Y' : 'N',
item.isDeleted ? 'Y' : '-',
item.note?.isEmpty ?? true ? '-' : item.note!,
item.updatedAt == null
? '-'
: dateFormat.format(item.updatedAt!.toLocal()),
].map((text) => ShadTableCell(child: Text(text))).toList();
cells.add(
ShadTableCell(
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
ShadButton.ghost(
size: ShadButtonSize.sm,
onPressed: onEdit == null ? null : () => onEdit!(item),
child: const Icon(LucideIcons.pencil, size: 16),
),
const SizedBox(width: 8),
item.isDeleted
? ShadButton.ghost(
size: ShadButtonSize.sm,
onPressed: onRestore == null
? null
: () => onRestore!(item),
child: const Icon(LucideIcons.history, size: 16),
)
: ShadButton.ghost(
size: ShadButtonSize.sm,
onPressed: onDelete == null
? null
: () => onDelete!(item),
child: const Icon(LucideIcons.trash2, size: 16),
),
],
),
),
);
return cells;
}).toList();
return SizedBox(
height: 56.0 * (menus.length + 1),
child: ShadTable.list(
header: header,
children: rows,
columnSpanExtent: (index) {
switch (index) {
case 4:
return const FixedTableSpanExtent(200);
case 7:
return const FixedTableSpanExtent(200);
case 9:
return const FixedTableSpanExtent(160);
default:
return const FixedTableSpanExtent(120);
}
},
),
);
}
}
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,
],
);
}