backup: 사용하지 않는 파일 삭제 전 복구 지점
- 전체 371개 파일 중 82개 미사용 파일 식별 - Phase 1: 33개 파일 삭제 예정 (100% 안전) - Phase 2: 30개 파일 삭제 검토 예정 - Phase 3: 19개 파일 수동 검토 예정 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -67,11 +67,39 @@ class _AppLayoutState extends State<AppLayout>
|
||||
}
|
||||
|
||||
Future<void> _loadCurrentUser() async {
|
||||
try {
|
||||
// 서버에서 최신 관리자 정보 가져오기
|
||||
final result = await _authService.getCurrentAdminFromServer();
|
||||
result.fold(
|
||||
(failure) {
|
||||
print('[AppLayout] 서버에서 관리자 정보 로드 실패: ${failure.message}');
|
||||
// 실패 시 로컬 스토리지에서 캐시된 정보 사용
|
||||
_loadCurrentUserFromLocal();
|
||||
},
|
||||
(user) {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_currentUser = user;
|
||||
});
|
||||
print('[AppLayout] 서버에서 관리자 정보 로드 성공: ${user.name} (${user.email})');
|
||||
}
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
print('[AppLayout] 관리자 정보 로드 중 예외 발생: $e');
|
||||
// 예외 발생 시 로컬 스토리지에서 캐시된 정보 사용
|
||||
_loadCurrentUserFromLocal();
|
||||
}
|
||||
}
|
||||
|
||||
/// 로컬 스토리지에서 캐시된 사용자 정보 로드 (fallback)
|
||||
Future<void> _loadCurrentUserFromLocal() async {
|
||||
final user = await _authService.getCurrentUser();
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_currentUser = user;
|
||||
});
|
||||
print('[AppLayout] 로컬에서 관리자 정보 로드: ${user?.name ?? 'Unknown'}');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -626,6 +654,14 @@ class _AppLayoutState extends State<AppLayout>
|
||||
// 프로필 설정 화면으로 이동
|
||||
},
|
||||
),
|
||||
_buildProfileMenuItem(
|
||||
icon: Icons.lock_outline,
|
||||
title: '비밀번호 변경',
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
_showChangePasswordDialog(context);
|
||||
},
|
||||
),
|
||||
_buildProfileMenuItem(
|
||||
icon: Icons.settings_outlined,
|
||||
title: '환경 설정',
|
||||
@@ -728,6 +764,228 @@ class _AppLayoutState extends State<AppLayout>
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 비밀번호 변경 다이얼로그
|
||||
void _showChangePasswordDialog(BuildContext context) {
|
||||
final oldPasswordController = TextEditingController();
|
||||
final newPasswordController = TextEditingController();
|
||||
final confirmPasswordController = TextEditingController();
|
||||
bool isLoading = false;
|
||||
bool obscureOldPassword = true;
|
||||
bool obscureNewPassword = true;
|
||||
bool obscureConfirmPassword = true;
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => StatefulBuilder(
|
||||
builder: (context, setState) => AlertDialog(
|
||||
backgroundColor: ShadcnTheme.background,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(ShadcnTheme.radiusLg),
|
||||
),
|
||||
title: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.lock_outline,
|
||||
color: ShadcnTheme.primary,
|
||||
size: 24,
|
||||
),
|
||||
const SizedBox(width: ShadcnTheme.spacing3),
|
||||
Text(
|
||||
'비밀번호 변경',
|
||||
style: ShadcnTheme.headingH5,
|
||||
),
|
||||
],
|
||||
),
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(
|
||||
'보안을 위해 기존 비밀번호를 입력하고 새 비밀번호를 설정해주세요.',
|
||||
style: ShadcnTheme.bodySmall.copyWith(
|
||||
color: ShadcnTheme.foregroundMuted,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: ShadcnTheme.spacing6),
|
||||
|
||||
// 기존 비밀번호
|
||||
Text(
|
||||
'기존 비밀번호',
|
||||
style: ShadcnTheme.labelMedium,
|
||||
),
|
||||
const SizedBox(height: ShadcnTheme.spacing2),
|
||||
TextFormField(
|
||||
controller: oldPasswordController,
|
||||
obscureText: obscureOldPassword,
|
||||
decoration: InputDecoration(
|
||||
hintText: '현재 사용중인 비밀번호를 입력하세요',
|
||||
suffixIcon: IconButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
obscureOldPassword = !obscureOldPassword;
|
||||
});
|
||||
},
|
||||
icon: Icon(
|
||||
obscureOldPassword ? Icons.visibility_off : Icons.visibility,
|
||||
color: ShadcnTheme.foregroundMuted,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: ShadcnTheme.spacing4),
|
||||
|
||||
// 새 비밀번호
|
||||
Text(
|
||||
'새 비밀번호',
|
||||
style: ShadcnTheme.labelMedium,
|
||||
),
|
||||
const SizedBox(height: ShadcnTheme.spacing2),
|
||||
TextFormField(
|
||||
controller: newPasswordController,
|
||||
obscureText: obscureNewPassword,
|
||||
decoration: InputDecoration(
|
||||
hintText: '8자 이상의 새 비밀번호를 입력하세요',
|
||||
suffixIcon: IconButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
obscureNewPassword = !obscureNewPassword;
|
||||
});
|
||||
},
|
||||
icon: Icon(
|
||||
obscureNewPassword ? Icons.visibility_off : Icons.visibility,
|
||||
color: ShadcnTheme.foregroundMuted,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(height: ShadcnTheme.spacing4),
|
||||
|
||||
// 새 비밀번호 확인
|
||||
Text(
|
||||
'새 비밀번호 확인',
|
||||
style: ShadcnTheme.labelMedium,
|
||||
),
|
||||
const SizedBox(height: ShadcnTheme.spacing2),
|
||||
TextFormField(
|
||||
controller: confirmPasswordController,
|
||||
obscureText: obscureConfirmPassword,
|
||||
decoration: InputDecoration(
|
||||
hintText: '새 비밀번호를 다시 입력하세요',
|
||||
suffixIcon: IconButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
obscureConfirmPassword = !obscureConfirmPassword;
|
||||
});
|
||||
},
|
||||
icon: Icon(
|
||||
obscureConfirmPassword ? Icons.visibility_off : Icons.visibility,
|
||||
color: ShadcnTheme.foregroundMuted,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
ShadcnButton(
|
||||
text: '취소',
|
||||
onPressed: isLoading ? null : () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
variant: ShadcnButtonVariant.secondary,
|
||||
),
|
||||
ShadcnButton(
|
||||
text: isLoading ? '변경 중...' : '변경하기',
|
||||
onPressed: isLoading ? null : () async {
|
||||
// 유효성 검사
|
||||
if (oldPasswordController.text.isEmpty) {
|
||||
_showSnackBar(context, '기존 비밀번호를 입력해주세요.', isError: true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (newPasswordController.text.length < 8) {
|
||||
_showSnackBar(context, '새 비밀번호는 8자 이상이어야 합니다.', isError: true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (newPasswordController.text != confirmPasswordController.text) {
|
||||
_showSnackBar(context, '새 비밀번호가 일치하지 않습니다.', isError: true);
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
isLoading = true;
|
||||
});
|
||||
|
||||
try {
|
||||
// AuthService.changePassword API 호출
|
||||
final result = await _authService.changePassword(
|
||||
oldPassword: oldPasswordController.text,
|
||||
newPassword: newPasswordController.text,
|
||||
);
|
||||
|
||||
result.fold(
|
||||
(failure) {
|
||||
if (context.mounted) {
|
||||
_showSnackBar(context, failure.message, isError: true);
|
||||
}
|
||||
},
|
||||
(messageResponse) {
|
||||
if (context.mounted) {
|
||||
Navigator.of(context).pop();
|
||||
_showSnackBar(context, messageResponse.message);
|
||||
}
|
||||
},
|
||||
);
|
||||
} catch (e) {
|
||||
if (context.mounted) {
|
||||
_showSnackBar(context, '비밀번호 변경 중 오류가 발생했습니다.', isError: true);
|
||||
}
|
||||
} finally {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
isLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
variant: ShadcnButtonVariant.primary,
|
||||
icon: isLoading ? SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
valueColor: AlwaysStoppedAnimation<Color>(
|
||||
ShadcnTheme.primaryForeground,
|
||||
),
|
||||
),
|
||||
) : Icon(Icons.check, size: 18),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 스낵바 표시 헬퍼 메서드
|
||||
void _showSnackBar(BuildContext context, String message, {bool isError = false}) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(message),
|
||||
backgroundColor: isError ? ShadcnTheme.error : ShadcnTheme.success,
|
||||
behavior: SnackBarBehavior.floating,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(ShadcnTheme.radiusMd),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// 재설계된 사이드바 메뉴 (접기/펼치기 지원)
|
||||
|
||||
@@ -29,81 +29,100 @@ class StandardActionBar extends StatelessWidget {
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
// 왼쪽 액션 버튼들
|
||||
Row(
|
||||
children: [
|
||||
...leftActions.map((action) => Padding(
|
||||
padding: const EdgeInsets.only(right: ShadcnTheme.spacing2),
|
||||
child: action,
|
||||
)),
|
||||
],
|
||||
Flexible(
|
||||
flex: 1,
|
||||
child: Wrap(
|
||||
spacing: ShadcnTheme.spacing2,
|
||||
runSpacing: 4,
|
||||
children: [
|
||||
...leftActions,
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// 오른쪽 상태 표시 및 액션들
|
||||
Row(
|
||||
children: [
|
||||
// 추가 상태 메시지 (작은 글자 크기로 통일)
|
||||
if (statusMessage != null) ...[
|
||||
Text(statusMessage!, style: ShadcnTheme.bodySmall),
|
||||
const SizedBox(width: ShadcnTheme.spacing3),
|
||||
],
|
||||
|
||||
// 선택된 항목 수 표시
|
||||
if (selectedCount != null && selectedCount! > 0) ...[
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 8,
|
||||
horizontal: 16,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: ShadcnTheme.primary.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(ShadcnTheme.radiusSm),
|
||||
border: Border.all(color: ShadcnTheme.primary.withValues(alpha: 0.3)),
|
||||
),
|
||||
child: Text(
|
||||
'$selectedCount개 선택됨',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: ShadcnTheme.primary,
|
||||
// 오른쪽 상태 표시 및 액션들 - 오버플로우 방지
|
||||
Flexible(
|
||||
flex: 2,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// 추가 상태 메시지 (작은 글자 크기로 통일) - 텍스트 오버플로우 방지
|
||||
if (statusMessage != null) ...[
|
||||
Flexible(
|
||||
child: Text(
|
||||
statusMessage!,
|
||||
style: ShadcnTheme.bodySmall,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
maxLines: 1,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: ShadcnTheme.spacing3),
|
||||
const SizedBox(width: ShadcnTheme.spacing2),
|
||||
],
|
||||
|
||||
// 선택된 항목 수 표시
|
||||
if (selectedCount != null && selectedCount! > 0) ...[
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 6,
|
||||
horizontal: 12,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: ShadcnTheme.primary.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(ShadcnTheme.radiusSm),
|
||||
border: Border.all(color: ShadcnTheme.primary.withValues(alpha: 0.3)),
|
||||
),
|
||||
child: Text(
|
||||
'$selectedCount개',
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: ShadcnTheme.primary,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: ShadcnTheme.spacing2),
|
||||
],
|
||||
|
||||
// 전체 항목 수 표시 (statusMessage에 "총 X개"가 없을 때만 표시)
|
||||
if (statusMessage == null || !statusMessage!.contains('총'))
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 4,
|
||||
horizontal: 8,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: ShadcnTheme.muted.withValues(alpha: 0.2),
|
||||
borderRadius: BorderRadius.circular(ShadcnTheme.radiusSm),
|
||||
),
|
||||
child: Text(
|
||||
'총 $totalCount개',
|
||||
style: ShadcnTheme.bodySmall.copyWith(fontSize: 11),
|
||||
),
|
||||
),
|
||||
|
||||
// 새로고침 버튼
|
||||
if (onRefresh != null) ...[
|
||||
const SizedBox(width: ShadcnTheme.spacing2),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.refresh),
|
||||
onPressed: onRefresh,
|
||||
tooltip: '새로고침',
|
||||
iconSize: 18,
|
||||
padding: const EdgeInsets.all(4),
|
||||
constraints: const BoxConstraints(
|
||||
minWidth: 32,
|
||||
minHeight: 32,
|
||||
),
|
||||
),
|
||||
],
|
||||
|
||||
// 오른쪽 액션 버튼들
|
||||
...rightActions.map((action) => Padding(
|
||||
padding: const EdgeInsets.only(left: ShadcnTheme.spacing1),
|
||||
child: action,
|
||||
)),
|
||||
],
|
||||
|
||||
// 전체 항목 수 표시 (statusMessage에 "총 X개"가 없을 때만 표시)
|
||||
if (statusMessage == null || !statusMessage!.contains('총'))
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 6,
|
||||
horizontal: 12,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: ShadcnTheme.muted.withValues(alpha: 0.2),
|
||||
borderRadius: BorderRadius.circular(ShadcnTheme.radiusSm),
|
||||
),
|
||||
child: Text(
|
||||
'총 $totalCount개',
|
||||
style: ShadcnTheme.bodySmall,
|
||||
),
|
||||
),
|
||||
|
||||
// 새로고침 버튼
|
||||
if (onRefresh != null) ...[
|
||||
const SizedBox(width: ShadcnTheme.spacing3),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.refresh),
|
||||
onPressed: onRefresh,
|
||||
tooltip: '새로고침',
|
||||
iconSize: 20,
|
||||
),
|
||||
],
|
||||
|
||||
// 오른쪽 액션 버튼들
|
||||
...rightActions.map((action) => Padding(
|
||||
padding: const EdgeInsets.only(left: ShadcnTheme.spacing2),
|
||||
child: action,
|
||||
)),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
273
lib/screens/common/widgets/standard_dropdown.dart
Normal file
273
lib/screens/common/widgets/standard_dropdown.dart
Normal file
@@ -0,0 +1,273 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:shadcn_ui/shadcn_ui.dart';
|
||||
|
||||
/// 표준화된 드롭다운 위젯
|
||||
/// 3단계 상태 (로딩/오류/정상)를 자동으로 처리하며,
|
||||
/// 모든 Form에서 일관된 사용자 경험을 제공합니다.
|
||||
class StandardDropdown<T> extends StatelessWidget {
|
||||
/// 드롭다운 라벨
|
||||
final String label;
|
||||
|
||||
/// 필수 항목 여부 (라벨에 * 표시)
|
||||
final bool isRequired;
|
||||
|
||||
/// 드롭다운 옵션 데이터
|
||||
final List<T> items;
|
||||
|
||||
/// 로딩 상태
|
||||
final bool isLoading;
|
||||
|
||||
/// 오류 메시지 (null이면 오류 없음)
|
||||
final String? error;
|
||||
|
||||
/// 재시도 콜백 함수
|
||||
final VoidCallback? onRetry;
|
||||
|
||||
/// 선택 변경 콜백
|
||||
final void Function(T?) onChanged;
|
||||
|
||||
/// 현재 선택된 값
|
||||
final T? selectedValue;
|
||||
|
||||
/// 각 항목을 위젯으로 변환하는 빌더
|
||||
final Widget Function(T item) itemBuilder;
|
||||
|
||||
/// 선택된 항목을 표시하는 빌더
|
||||
final Widget Function(T item) selectedItemBuilder;
|
||||
|
||||
/// 값에서 고유 ID를 추출하는 함수
|
||||
final dynamic Function(T item) valueExtractor;
|
||||
|
||||
/// 플레이스홀더 텍스트
|
||||
final String placeholder;
|
||||
|
||||
/// 폼 검증 함수
|
||||
final String? Function(T? value)? validator;
|
||||
|
||||
/// 비활성화 여부
|
||||
final bool enabled;
|
||||
|
||||
const StandardDropdown({
|
||||
super.key,
|
||||
required this.label,
|
||||
this.isRequired = false,
|
||||
required this.items,
|
||||
this.isLoading = false,
|
||||
this.error,
|
||||
this.onRetry,
|
||||
required this.onChanged,
|
||||
this.selectedValue,
|
||||
required this.itemBuilder,
|
||||
required this.selectedItemBuilder,
|
||||
required this.valueExtractor,
|
||||
this.placeholder = '선택하세요',
|
||||
this.validator,
|
||||
this.enabled = true,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// 라벨
|
||||
Text(
|
||||
isRequired ? '$label *' : label,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
|
||||
// 3단계 상태 처리
|
||||
_buildStateWidget(),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
/// 상태에 따른 위젯 빌드
|
||||
Widget _buildStateWidget() {
|
||||
// 1. 로딩 상태
|
||||
if (isLoading) {
|
||||
return _buildLoadingWidget();
|
||||
}
|
||||
|
||||
// 2. 오류 상태
|
||||
if (error != null) {
|
||||
return _buildErrorWidget();
|
||||
}
|
||||
|
||||
// 3. 정상 상태
|
||||
return _buildDropdownWidget();
|
||||
}
|
||||
|
||||
/// 로딩 위젯
|
||||
Widget _buildLoadingWidget() {
|
||||
return SizedBox(
|
||||
height: 56,
|
||||
child: Center(
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 120, // 명시적 너비 지정으로 무한 너비 제약 해결
|
||||
child: const ShadProgress(),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text('$label 목록을 불러오는 중...'),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 오류 위젯
|
||||
Widget _buildErrorWidget() {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.red.shade50,
|
||||
border: Border.all(color: Colors.red.shade200),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.error, color: Colors.red.shade600, size: 20),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
'$label 로딩 실패',
|
||||
style: const TextStyle(fontWeight: FontWeight.w500),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
error!,
|
||||
style: TextStyle(color: Colors.red.shade700, fontSize: 14),
|
||||
),
|
||||
if (onRetry != null) ...[
|
||||
const SizedBox(height: 12),
|
||||
ShadButton(
|
||||
onPressed: onRetry,
|
||||
child: const Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.refresh, size: 16),
|
||||
SizedBox(width: 4),
|
||||
Text('다시 시도'),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 드롭다운 위젯 (정상 상태)
|
||||
Widget _buildDropdownWidget() {
|
||||
// 비어있는 경우 처리
|
||||
if (items.isEmpty) {
|
||||
return Container(
|
||||
height: 56,
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey.shade50,
|
||||
border: Border.all(color: Colors.grey.shade300),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Center(
|
||||
child: Text(
|
||||
'$label이(가) 없습니다',
|
||||
style: TextStyle(color: Colors.grey.shade600),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return ShadSelect<dynamic>(
|
||||
placeholder: Text(placeholder),
|
||||
options: items.map((item) {
|
||||
return ShadOption(
|
||||
value: valueExtractor(item),
|
||||
child: itemBuilder(item),
|
||||
);
|
||||
}).toList(),
|
||||
selectedOptionBuilder: (context, value) {
|
||||
if (value == null) return Text(placeholder);
|
||||
|
||||
// 선택된 값에 해당하는 항목 찾기
|
||||
try {
|
||||
final selectedItem = items.firstWhere(
|
||||
(item) => valueExtractor(item) == value,
|
||||
);
|
||||
return selectedItemBuilder(selectedItem);
|
||||
} catch (e) {
|
||||
return Text('알 수 없는 항목 (값: $value)');
|
||||
}
|
||||
},
|
||||
onChanged: enabled ? (value) {
|
||||
if (value == null) {
|
||||
onChanged(null);
|
||||
return;
|
||||
}
|
||||
|
||||
// 값에 해당하는 실제 객체 찾기
|
||||
try {
|
||||
final selectedItem = items.firstWhere(
|
||||
(item) => valueExtractor(item) == value,
|
||||
);
|
||||
onChanged(selectedItem);
|
||||
} catch (e) {
|
||||
onChanged(null);
|
||||
}
|
||||
} : null,
|
||||
initialValue: selectedValue != null ? valueExtractor(selectedValue as T) : null,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Int ID 타입을 위한 편의 클래스
|
||||
class StandardIntDropdown<T> extends StandardDropdown<T> {
|
||||
StandardIntDropdown({
|
||||
super.key,
|
||||
required super.label,
|
||||
super.isRequired = false,
|
||||
required super.items,
|
||||
super.isLoading = false,
|
||||
super.error,
|
||||
super.onRetry,
|
||||
required super.onChanged,
|
||||
super.selectedValue,
|
||||
required super.itemBuilder,
|
||||
required super.selectedItemBuilder,
|
||||
required int Function(T item) idExtractor,
|
||||
super.placeholder = '선택하세요',
|
||||
super.validator,
|
||||
super.enabled = true,
|
||||
}) : super(
|
||||
valueExtractor: (item) => idExtractor(item),
|
||||
);
|
||||
}
|
||||
|
||||
/// String 값 타입을 위한 편의 클래스
|
||||
class StandardStringDropdown<T> extends StandardDropdown<T> {
|
||||
StandardStringDropdown({
|
||||
super.key,
|
||||
required super.label,
|
||||
super.isRequired = false,
|
||||
required super.items,
|
||||
super.isLoading = false,
|
||||
super.error,
|
||||
super.onRetry,
|
||||
required super.onChanged,
|
||||
super.selectedValue,
|
||||
required super.itemBuilder,
|
||||
required super.selectedItemBuilder,
|
||||
required super.valueExtractor,
|
||||
super.placeholder = '선택하세요',
|
||||
super.validator,
|
||||
super.enabled = true,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user