이벤트 개발완료
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
|
||||
import '../../utils/event_excel_parser.dart';
|
||||
import '../../utils/event_csv_parser.dart';
|
||||
@@ -17,6 +15,7 @@ import '../../widgets/loading_indicator.dart';
|
||||
import 'event_details_screen.dart';
|
||||
import 'event_form_screen.dart';
|
||||
import 'event_calendar_screen.dart';
|
||||
import 'event_import_wizard.dart';
|
||||
import '../../widgets/dialog_actions.dart';
|
||||
import '../../widgets/import_result_dialog.dart';
|
||||
import '../../theme/badges.dart';
|
||||
@@ -37,6 +36,23 @@ class _EventsScreenState extends State<EventsScreen> {
|
||||
String _filterStatus = '모든 상태'; // '모든 상태', '활성', '대기', '취소', '완료'
|
||||
String _sortBy = '날짜순'; // '날짜순', '이름순'
|
||||
|
||||
// 이벤트 상태 정규화: DB 원시값(영문) -> 한국어 라벨
|
||||
String? _normalizeEventStatus(String? status) {
|
||||
if (status == null) return null;
|
||||
final s = status.toLowerCase().trim();
|
||||
if (s == 'active' || s == 'enabled' || s == '활성') return '활성';
|
||||
if (s == 'pending' ||
|
||||
s == 'draft' ||
|
||||
s == 'scheduled' ||
|
||||
s == 'waiting' ||
|
||||
s == '대기')
|
||||
return '대기';
|
||||
if (s == 'canceled' || s == 'cancelled' || s == '취소') return '취소';
|
||||
if (s == 'completed' || s == 'done' || s == 'finished' || s == '완료')
|
||||
return '완료';
|
||||
return status; // 알 수 없는 값은 원문 유지
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_searchController.dispose();
|
||||
@@ -83,29 +99,32 @@ class _EventsScreenState extends State<EventsScreen> {
|
||||
navigator.pop();
|
||||
messenger.showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('파일 파싱 중 오류가 발생했습니다: ${e.toString()}\n가능하면 CSV 또는 XLSX 형식을 사용해 주세요.'),
|
||||
content: Text(
|
||||
'파일 파싱 중 오류가 발생했습니다: ${e.toString()}\n가능하면 CSV 또는 XLSX 형식을 사용해 주세요.',
|
||||
),
|
||||
duration: Duration(seconds: 5),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
final processedRows = parseResult['processedRows'] as int;
|
||||
final events = (parseResult['validEvents'] as List).cast<Map<String, dynamic>>();
|
||||
final events = (parseResult['validEvents'] as List)
|
||||
.cast<Map<String, dynamic>>();
|
||||
final invalidRows = parseResult['invalidRows'] as int;
|
||||
final invalidRowIndices = (parseResult['invalidRowIndices'] as List<dynamic>? ?? const [])
|
||||
.map((e) => e.toString())
|
||||
.toList();
|
||||
final Map<String, String> invalidRowReasons = ((parseResult['invalidRowReasons'] as Map?) ?? const {})
|
||||
.map((key, value) => MapEntry(key.toString(), value?.toString() ?? ''));
|
||||
final invalidRowIndices =
|
||||
(parseResult['invalidRowIndices'] as List<dynamic>? ?? const [])
|
||||
.map((e) => e.toString())
|
||||
.toList();
|
||||
final Map<String, String> invalidRowReasons =
|
||||
((parseResult['invalidRowReasons'] as Map?) ?? const {}).map(
|
||||
(key, value) => MapEntry(key.toString(), value?.toString() ?? ''),
|
||||
);
|
||||
final error = parseResult['error'] as String?;
|
||||
|
||||
if (error != null) {
|
||||
navigator.pop();
|
||||
messenger.showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(error),
|
||||
duration: Duration(seconds: 4),
|
||||
),
|
||||
SnackBar(content: Text(error), duration: Duration(seconds: 4)),
|
||||
);
|
||||
return;
|
||||
}
|
||||
@@ -205,15 +224,11 @@ class _EventsScreenState extends State<EventsScreen> {
|
||||
eventService.setClubId(event.clubId);
|
||||
await eventService.cloneEvent(event.id);
|
||||
if (!mounted) return;
|
||||
messenger.showSnackBar(
|
||||
const SnackBar(content: Text('이벤트가 복제되었습니다')),
|
||||
);
|
||||
messenger.showSnackBar(const SnackBar(content: Text('이벤트가 복제되었습니다')));
|
||||
// 목록 새로고침
|
||||
await _loadEvents();
|
||||
} catch (e) {
|
||||
messenger.showSnackBar(
|
||||
SnackBar(content: Text('이벤트 복제에 실패했습니다: $e')),
|
||||
);
|
||||
messenger.showSnackBar(SnackBar(content: Text('이벤트 복제에 실패했습니다: $e')));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,6 +242,18 @@ class _EventsScreenState extends State<EventsScreen> {
|
||||
}
|
||||
|
||||
Future<void> _loadEvents() async {
|
||||
// 인증 가드: 로그인 상태가 아니면 목록 로딩을 시도하지 않음
|
||||
final authService = Provider.of<AuthService>(context, listen: false);
|
||||
if (!authService.isAuthenticated) {
|
||||
// 필요 시 간단 안내만 표시하고 리턴
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('로그인이 필요합니다. 로그인 후 이벤트를 불러옵니다.')),
|
||||
);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_isLoading = true;
|
||||
});
|
||||
@@ -234,7 +261,6 @@ class _EventsScreenState extends State<EventsScreen> {
|
||||
// 비동기 갭 이후 컨텍스트 직접 참조를 피하기 위해 메신저 캡처
|
||||
final messenger = ScaffoldMessenger.of(context);
|
||||
try {
|
||||
final authService = Provider.of<AuthService>(context, listen: false);
|
||||
final clubService = Provider.of<ClubService>(context, listen: false);
|
||||
final eventService = Provider.of<EventService>(context, listen: false);
|
||||
|
||||
@@ -244,9 +270,19 @@ class _EventsScreenState extends State<EventsScreen> {
|
||||
}
|
||||
} catch (e) {
|
||||
if (!context.mounted) return;
|
||||
messenger.showSnackBar(
|
||||
SnackBar(content: Text('이벤트 목록을 불러오는데 실패했습니다: $e')),
|
||||
);
|
||||
final msg = e.toString();
|
||||
// 401/인증 관련 메시지에 대한 UX 보강
|
||||
if (msg.contains('401') || msg.contains('인증') || msg.contains('토큰')) {
|
||||
messenger.showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('세션이 만료되었거나 인증 정보가 유효하지 않습니다. 다시 로그인해 주세요.'),
|
||||
),
|
||||
);
|
||||
} else {
|
||||
messenger.showSnackBar(
|
||||
SnackBar(content: Text('이벤트 목록을 불러오는데 실패했습니다: $e')),
|
||||
);
|
||||
}
|
||||
} finally {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
@@ -283,7 +319,9 @@ class _EventsScreenState extends State<EventsScreen> {
|
||||
// 상태 필터링
|
||||
if (_filterStatus != '모든 상태') {
|
||||
filteredEvents = filteredEvents
|
||||
.where((event) => event.status == _filterStatus)
|
||||
.where(
|
||||
(event) => _normalizeEventStatus(event.status) == _filterStatus,
|
||||
)
|
||||
.toList();
|
||||
}
|
||||
|
||||
@@ -300,38 +338,30 @@ class _EventsScreenState extends State<EventsScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('이벤트'),
|
||||
actions: [
|
||||
IconButton(
|
||||
tooltip: '캘린더 보기',
|
||||
icon: const Icon(Icons.calendar_today),
|
||||
onPressed: _navigateToCalendarView,
|
||||
),
|
||||
IconButton(
|
||||
tooltip: '파일에서 생성',
|
||||
icon: const Icon(Icons.file_upload),
|
||||
onPressed: _showFileUploadDialog,
|
||||
),
|
||||
IconButton(
|
||||
tooltip: '이벤트 추가',
|
||||
icon: const Icon(Icons.add),
|
||||
onPressed: _showAddEventDialog,
|
||||
),
|
||||
],
|
||||
),
|
||||
body: _isLoading
|
||||
? const LoadingIndicator()
|
||||
: Column(
|
||||
children: [
|
||||
// 상단 버튼 영역
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16.0, 16.0, 16.0, 0),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.end,
|
||||
children: [
|
||||
OutlinedButton.icon(
|
||||
onPressed: _navigateToCalendarView,
|
||||
icon: const Icon(Icons.calendar_today),
|
||||
label: const Text('캘린더 보기'),
|
||||
style: OutlinedButton.styleFrom(
|
||||
foregroundColor: Colors.blue,
|
||||
side: const BorderSide(color: Colors.blue),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
OutlinedButton.icon(
|
||||
onPressed: _showFileUploadDialog,
|
||||
icon: const Icon(Icons.file_upload),
|
||||
label: const Text('파일에서 생성'),
|
||||
style: OutlinedButton.styleFrom(
|
||||
foregroundColor: Colors.blue,
|
||||
side: const BorderSide(color: Colors.blue),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
// 검색 바
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
@@ -470,11 +500,7 @@ class _EventsScreenState extends State<EventsScreen> {
|
||||
),
|
||||
],
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: _showAddEventDialog,
|
||||
backgroundColor: Colors.blue,
|
||||
child: const Icon(Icons.add, color: Colors.white),
|
||||
),
|
||||
// FAB 제거: AppBar actions로 이동
|
||||
);
|
||||
}
|
||||
|
||||
@@ -563,9 +589,7 @@ class _EventsScreenState extends State<EventsScreen> {
|
||||
Wrap(
|
||||
spacing: 4,
|
||||
runSpacing: 4,
|
||||
children: [
|
||||
BadgeStyles.eventStatus(event.status!),
|
||||
],
|
||||
children: [BadgeStyles.eventStatus(event.status!)],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
],
|
||||
@@ -596,6 +620,8 @@ class _EventsScreenState extends State<EventsScreen> {
|
||||
_showDeleteConfirmationDialog(event);
|
||||
} else if (value == 'duplicate') {
|
||||
_duplicateEvent(event);
|
||||
} else if (value == 'permanent_delete') {
|
||||
_showPermanentDeleteConfirmationDialog(event);
|
||||
}
|
||||
},
|
||||
itemBuilder: (context) => [
|
||||
@@ -623,9 +649,19 @@ class _EventsScreenState extends State<EventsScreen> {
|
||||
value: 'delete',
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.delete, size: 18, color: Colors.red),
|
||||
Icon(Icons.visibility_off, size: 18),
|
||||
SizedBox(width: 8),
|
||||
Text('삭제', style: TextStyle(color: Colors.red)),
|
||||
Text('숨김'),
|
||||
],
|
||||
),
|
||||
),
|
||||
const PopupMenuItem<String>(
|
||||
value: 'permanent_delete',
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.delete_forever, size: 18, color: Colors.red),
|
||||
SizedBox(width: 8),
|
||||
Text('완전 삭제', style: TextStyle(color: Colors.red)),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -741,9 +777,9 @@ class _EventsScreenState extends State<EventsScreen> {
|
||||
onConfirm: () async {
|
||||
if (titleController.text.isEmpty) {
|
||||
if (!context.mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('제목은 필수 입력 항목입니다')),
|
||||
);
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(const SnackBar(content: Text('제목은 필수 입력 항목입니다')));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -775,14 +811,14 @@ class _EventsScreenState extends State<EventsScreen> {
|
||||
|
||||
if (!context.mounted) return;
|
||||
Navigator.of(context).pop();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('이벤트가 업데이트되었습니다')),
|
||||
);
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(const SnackBar(content: Text('이벤트가 업데이트되었습니다')));
|
||||
} catch (e) {
|
||||
if (!context.mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('이벤트 업데이트에 실패했습니다: $e')),
|
||||
);
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text('이벤트 업데이트에 실패했습니다: $e')));
|
||||
}
|
||||
},
|
||||
confirmText: '저장',
|
||||
@@ -810,8 +846,8 @@ class _EventsScreenState extends State<EventsScreen> {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('이벤트 삭제'),
|
||||
content: Text('${event.title} 이벤트를 정말 삭제하시겠습니까?'),
|
||||
title: const Text('이벤트 숨김'),
|
||||
content: Text('${event.title} 이벤트를 목록에서 숨길까요? (소프트 삭제)'),
|
||||
actions: DialogActions.confirm(
|
||||
onCancel: () => Navigator.of(context).pop(),
|
||||
onConfirm: () async {
|
||||
@@ -823,273 +859,79 @@ class _EventsScreenState extends State<EventsScreen> {
|
||||
await eventService.deleteEvent(event.id);
|
||||
if (!context.mounted) return;
|
||||
Navigator.of(context).pop();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('이벤트가 삭제되었습니다')),
|
||||
);
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(const SnackBar(content: Text('이벤트가 숨김 처리되었습니다')));
|
||||
} catch (e) {
|
||||
if (!context.mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('이벤트 삭제에 실패했습니다: $e')),
|
||||
);
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text('이벤트 숨김에 실패했습니다: $e')));
|
||||
}
|
||||
},
|
||||
destructive: true,
|
||||
confirmText: '삭제',
|
||||
destructive: false,
|
||||
confirmText: '숨김',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// 캘린더 보기 화면으로 이동
|
||||
void _navigateToCalendarView() {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute(builder: (context) => const EventCalendarScreen()),
|
||||
);
|
||||
}
|
||||
|
||||
// 파일에서 이벤트 생성 다이얼로그 표시
|
||||
void _showFileUploadDialog() {
|
||||
void _showPermanentDeleteConfirmationDialog(Event event) {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('파일에서 이벤트 생성'),
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Text('엑셀 파일(.xlsx, .xls)에서 이벤트를 일괄 생성할 수 있습니다.'),
|
||||
const SizedBox(height: 16),
|
||||
const Text(
|
||||
'파일 형식 안내:',
|
||||
style: TextStyle(fontWeight: FontWeight.bold),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
const Text(
|
||||
'• 첫 번째 행은 헤더로 사용됩니다.',
|
||||
style: TextStyle(fontSize: 14),
|
||||
),
|
||||
const Text(
|
||||
'• 필수 필드: title(이벤트 제목), startDate(시작일)',
|
||||
style: TextStyle(fontSize: 14),
|
||||
),
|
||||
const Text(
|
||||
'• 선택 필드: description(설명), location(장소), endDate(종료일), status(상태)',
|
||||
style: TextStyle(fontSize: 14),
|
||||
),
|
||||
const Text(
|
||||
'• 날짜 형식: YYYY-MM-DD 또는 YYYY/MM/DD',
|
||||
style: TextStyle(fontSize: 14),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: ElevatedButton.icon(
|
||||
onPressed: _pickAndUploadFile,
|
||||
icon: const Icon(Icons.file_upload),
|
||||
label: const Text('파일 선택'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Theme.of(context).primaryColor,
|
||||
foregroundColor: Colors.white,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
TextButton.icon(
|
||||
onPressed: () async {
|
||||
// 번들된 CSV 템플릿을 읽어 공유
|
||||
final data = await rootBundle.loadString('assets/templates/event_import_template.csv');
|
||||
await SharePlus.instance.share(
|
||||
ShareParams(
|
||||
text: data,
|
||||
subject: 'Event Import Template.csv',
|
||||
),
|
||||
);
|
||||
},
|
||||
icon: const Icon(Icons.download),
|
||||
label: const Text('예시 템플릿 다운로드'),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
TextButton.icon(
|
||||
onPressed: () async {
|
||||
const headers = 'title,startDate,endDate,description,location,status,type,maxParticipants';
|
||||
await Clipboard.setData(const ClipboardData(text: headers));
|
||||
if (!context.mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('CSV 헤더가 클립보드에 복사되었습니다.')),
|
||||
);
|
||||
},
|
||||
icon: const Icon(Icons.copy_all),
|
||||
label: const Text('CSV 헤더 복사'),
|
||||
),
|
||||
],
|
||||
),
|
||||
title: const Text('이벤트 완전 삭제'),
|
||||
content: Text(
|
||||
'정말 "${event.title}" 이벤트를 완전 삭제하시겠습니까?\n이 작업은 되돌릴 수 없으며 관련된 팀, 점수, 참가자 데이터가 모두 삭제됩니다.',
|
||||
),
|
||||
actions: DialogActions.confirm(
|
||||
onCancel: () => Navigator.of(context).pop(),
|
||||
onConfirm: () => Navigator.of(context).pop(),
|
||||
confirmText: '닫기',
|
||||
onConfirm: () async {
|
||||
try {
|
||||
final eventService = Provider.of<EventService>(
|
||||
context,
|
||||
listen: false,
|
||||
);
|
||||
await eventService.deleteEventPermanently(event.id);
|
||||
if (!context.mounted) return;
|
||||
Navigator.of(context).pop();
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(const SnackBar(content: Text('이벤트가 완전 삭제되었습니다')));
|
||||
} catch (e) {
|
||||
if (!context.mounted) return;
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text('이벤트 완전 삭제에 실패했습니다: $e')));
|
||||
}
|
||||
},
|
||||
destructive: true,
|
||||
confirmText: '완전 삭제',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// 파일 선택 및 업로드
|
||||
Future<void> _pickAndUploadFile() async {
|
||||
// 비동기 전 context 및 파생 객체 캡처 (use_build_context_synchronously 회피)
|
||||
final ctx = context;
|
||||
final navigator = Navigator.of(ctx);
|
||||
final messenger = ScaffoldMessenger.of(ctx);
|
||||
final eventService = Provider.of<EventService>(ctx, listen: false);
|
||||
try {
|
||||
// 파일 피커를 사용하여 엑셀 파일 선택
|
||||
final result = await FilePicker.platform.pickFiles(
|
||||
type: FileType.custom,
|
||||
allowedExtensions: ['xlsx', 'xls', 'csv'],
|
||||
allowMultiple: false,
|
||||
);
|
||||
// 캘린더 보기 네비게이션
|
||||
void _navigateToCalendarView() {
|
||||
Navigator.of(
|
||||
context,
|
||||
).push(MaterialPageRoute(builder: (_) => const EventCalendarScreen()));
|
||||
}
|
||||
|
||||
if (result == null || result.files.isEmpty) {
|
||||
// 사용자가 파일 선택을 취소함
|
||||
return;
|
||||
}
|
||||
|
||||
final file = result.files.first;
|
||||
final fileName = file.name;
|
||||
final bytes = file.bytes;
|
||||
|
||||
if (bytes == null) {
|
||||
messenger.showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('파일을 읽을 수 없습니다. 다른 파일을 선택해주세요.'),
|
||||
duration: Duration(seconds: 3),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// 로딩 다이얼로그 표시
|
||||
if (!ctx.mounted) return;
|
||||
showDialog(
|
||||
context: ctx,
|
||||
barrierDismissible: false,
|
||||
builder: (_) => AlertDialog(
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const CircularProgressIndicator(),
|
||||
const SizedBox(height: 16),
|
||||
Text('파일 "$fileName" 처리 중...'),
|
||||
const SizedBox(height: 8),
|
||||
const Text('이벤트 데이터를 추출하고 있습니다.'),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// 확장자에 따라 CSV/엑셀 파서 분기 + 안전 처리
|
||||
Map<String, dynamic> parseResult;
|
||||
final lower = fileName.toLowerCase();
|
||||
try {
|
||||
if (lower.endsWith('.csv')) {
|
||||
parseResult = EventCsvParser.parseCsvBytes(bytes);
|
||||
} else {
|
||||
parseResult = EventExcelParser.parseExcelBytes(bytes);
|
||||
}
|
||||
} catch (e) {
|
||||
navigator.pop();
|
||||
messenger.showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('파일 파싱 중 오류가 발생했습니다: ${e.toString()}\n가능하면 CSV 또는 XLSX 형식을 사용해 주세요.'),
|
||||
duration: const Duration(seconds: 5),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
final processedRows = parseResult['processedRows'] as int;
|
||||
final events = parseResult['validEvents'] as List<Map<String, dynamic>>;
|
||||
final invalidRows = parseResult['invalidRows'] as int;
|
||||
final invalidRowIndices = (parseResult['invalidRowIndices'] as List<dynamic>? ?? const [])
|
||||
.map((e) => e.toString())
|
||||
.toList();
|
||||
final Map<String, String> invalidRowReasons = ((parseResult['invalidRowReasons'] as Map?) ?? const {})
|
||||
.map((key, value) => MapEntry(key.toString(), value?.toString() ?? ''));
|
||||
final error = parseResult['error'] as String?;
|
||||
|
||||
// 오류가 있거나 이벤트가 없는 경우
|
||||
if (error != null) {
|
||||
// 로딩 다이얼로그 닫기 및 에러 스낵바 표시
|
||||
navigator.pop();
|
||||
messenger.showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(error),
|
||||
duration: const Duration(seconds: 4),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// 로딩 다이얼로그 업데이트
|
||||
if (!ctx.mounted) {
|
||||
if (navigator.canPop()) navigator.pop();
|
||||
return;
|
||||
}
|
||||
navigator.pop();
|
||||
if (!ctx.mounted) return;
|
||||
showDialog(
|
||||
context: ctx,
|
||||
barrierDismissible: false,
|
||||
builder: (_) => AlertDialog(
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const CircularProgressIndicator(),
|
||||
const SizedBox(height: 16),
|
||||
Text('이벤트 ${events.length}개 생성 중...'),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// 이벤트 서비스를 통해 이벤트 생성 (비동기 이전에 캡처해 둔 것을 사용)
|
||||
final results = await eventService.createEventsFromFile(events);
|
||||
|
||||
// 로딩 다이얼로그 닫기
|
||||
if (navigator.canPop()) navigator.pop();
|
||||
|
||||
// 결과 표시
|
||||
if (!ctx.mounted) return;
|
||||
// 상세 결과 다이얼로그 표시
|
||||
if (!ctx.mounted) return;
|
||||
showDialog(
|
||||
context: ctx,
|
||||
builder: (dialogContext) => ImportResultDialog(
|
||||
fileName: fileName,
|
||||
processedRows: processedRows,
|
||||
createdCount: results.length,
|
||||
invalidRows: invalidRows,
|
||||
invalidRowIndices: invalidRowIndices,
|
||||
invalidRowReasons: invalidRowReasons,
|
||||
onClose: () {
|
||||
Navigator.of(dialogContext).pop();
|
||||
// 파일에서 생성 → 가져오기 마법사로 이동
|
||||
void _showFileUploadDialog() {
|
||||
Navigator.of(context)
|
||||
.push(MaterialPageRoute(builder: (_) => const EventImportWizard()))
|
||||
.then((result) {
|
||||
if (result != null) {
|
||||
_loadEvents();
|
||||
},
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
// 로딩 다이얼로그가 열려 있으면 닫기
|
||||
if (navigator.canPop()) navigator.pop();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 사용자 친화적인 오류 메시지 표시 (messenger는 사전 캡처되어 context 불필요)
|
||||
messenger.showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('파일 처리 중 오류가 발생했습니다: $e'),
|
||||
duration: const Duration(seconds: 4),
|
||||
),
|
||||
);
|
||||
}
|
||||
// 호환성: 레거시 참조용 별칭 (내부적으로 마법사 호출)
|
||||
void _pickAndUploadFile() {
|
||||
_showFileUploadDialog();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user