이벤트 가져오기 위젯 테스트 추가 및 테스트 훅 도입
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
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';
|
||||
import '../../services/auth_service.dart';
|
||||
import '../../services/club_service.dart';
|
||||
|
||||
@@ -13,6 +17,9 @@ import '../../widgets/loading_indicator.dart';
|
||||
import 'event_details_screen.dart';
|
||||
import 'event_form_screen.dart';
|
||||
import 'event_calendar_screen.dart';
|
||||
import '../../widgets/dialog_actions.dart';
|
||||
import '../../widgets/import_result_dialog.dart';
|
||||
import '../../theme/badges.dart';
|
||||
|
||||
class EventsScreen extends StatefulWidget {
|
||||
const EventsScreen({super.key});
|
||||
@@ -36,11 +43,185 @@ class _EventsScreenState extends State<EventsScreen> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
/// 테스트 전용: 파일명을 포함한 바이트 데이터를 직접 주입해 업로드 플로우를 실행
|
||||
@visibleForTesting
|
||||
Future<void> importFromBytesForTest(String fileName, List<int> bytes) async {
|
||||
final ctx = context;
|
||||
final navigator = Navigator.of(ctx);
|
||||
final messenger = ScaffoldMessenger.of(ctx);
|
||||
final eventService = Provider.of<EventService>(ctx, listen: false);
|
||||
try {
|
||||
// 로딩 다이얼로그 표시
|
||||
if (!ctx.mounted) return;
|
||||
showDialog(
|
||||
context: ctx,
|
||||
barrierDismissible: false,
|
||||
builder: (_) => const AlertDialog(
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
CircularProgressIndicator(),
|
||||
SizedBox(height: 16),
|
||||
Text('파일 처리 중...'),
|
||||
SizedBox(height: 8),
|
||||
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: Duration(seconds: 5),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
final processedRows = parseResult['processedRows'] as int;
|
||||
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 error = parseResult['error'] as String?;
|
||||
|
||||
if (error != null) {
|
||||
navigator.pop();
|
||||
messenger.showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(error),
|
||||
duration: 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;
|
||||
showDialog(
|
||||
context: ctx,
|
||||
builder: (dialogContext) => ImportResultDialog(
|
||||
fileName: fileName,
|
||||
processedRows: processedRows,
|
||||
createdCount: results.length,
|
||||
invalidRows: invalidRows,
|
||||
invalidRowIndices: invalidRowIndices,
|
||||
invalidRowReasons: invalidRowReasons,
|
||||
onClose: () {
|
||||
Navigator.of(dialogContext).pop();
|
||||
_loadEvents();
|
||||
},
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
if (navigator.canPop()) navigator.pop();
|
||||
messenger.showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('파일 처리 중 오류가 발생했습니다: $e'),
|
||||
duration: const Duration(seconds: 4),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 테스트 편의를 위한 공개 훅: 오버레이 없이 복제 플로우를 직접 호출
|
||||
@visibleForTesting
|
||||
Future<void> invokeDuplicateForTest(Event event) async {
|
||||
final eventService = Provider.of<EventService>(context, listen: false);
|
||||
eventService.setClubId(event.clubId);
|
||||
await eventService.cloneEvent(event.id);
|
||||
}
|
||||
|
||||
// 검색어 복원
|
||||
Future<void> _restoreSearchQuery() async {
|
||||
try {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
final saved = prefs.getString('events_search_query') ?? '';
|
||||
if (saved.isNotEmpty) {
|
||||
_searchController.text = saved;
|
||||
_searchQuery = saved;
|
||||
}
|
||||
} catch (_) {
|
||||
// ignore restore errors
|
||||
}
|
||||
}
|
||||
|
||||
// 검색어 저장
|
||||
Future<void> _saveSearchQuery(String value) async {
|
||||
try {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setString('events_search_query', value);
|
||||
} catch (_) {
|
||||
// ignore save errors
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _duplicateEvent(Event event) async {
|
||||
final messenger = ScaffoldMessenger.of(context);
|
||||
try {
|
||||
final eventService = Provider.of<EventService>(context, listen: false);
|
||||
// cloneEvent는 clubId가 필요하므로 보장 차원에서 주입
|
||||
eventService.setClubId(event.clubId);
|
||||
await eventService.cloneEvent(event.id);
|
||||
if (!mounted) return;
|
||||
messenger.showSnackBar(
|
||||
const SnackBar(content: Text('이벤트가 복제되었습니다')),
|
||||
);
|
||||
// 목록 새로고침
|
||||
await _loadEvents();
|
||||
} catch (e) {
|
||||
messenger.showSnackBar(
|
||||
SnackBar(content: Text('이벤트 복제에 실패했습니다: $e')),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
if (!_isInit) {
|
||||
_loadEvents();
|
||||
_restoreSearchQuery().then((_) => _loadEvents());
|
||||
_isInit = true;
|
||||
}
|
||||
}
|
||||
@@ -50,6 +231,8 @@ class _EventsScreenState extends State<EventsScreen> {
|
||||
_isLoading = true;
|
||||
});
|
||||
|
||||
// 비동기 갭 이후 컨텍스트 직접 참조를 피하기 위해 메신저 캡처
|
||||
final messenger = ScaffoldMessenger.of(context);
|
||||
try {
|
||||
final authService = Provider.of<AuthService>(context, listen: false);
|
||||
final clubService = Provider.of<ClubService>(context, listen: false);
|
||||
@@ -60,11 +243,10 @@ class _EventsScreenState extends State<EventsScreen> {
|
||||
await eventService.fetchClubEvents();
|
||||
}
|
||||
} catch (e) {
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text('이벤트 목록을 불러오는데 실패했습니다: $e')));
|
||||
}
|
||||
if (!context.mounted) return;
|
||||
messenger.showSnackBar(
|
||||
SnackBar(content: Text('이벤트 목록을 불러오는데 실패했습니다: $e')),
|
||||
);
|
||||
} finally {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
@@ -182,6 +364,7 @@ class _EventsScreenState extends State<EventsScreen> {
|
||||
setState(() {
|
||||
_searchQuery = value;
|
||||
});
|
||||
_saveSearchQuery(value);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
@@ -369,11 +552,23 @@ class _EventsScreenState extends State<EventsScreen> {
|
||||
fontWeight: FontWeight.bold,
|
||||
color: isPast ? Colors.grey[600] : Colors.black,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
subtitle: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const SizedBox(height: 4),
|
||||
if (event.status != null) ...[
|
||||
Wrap(
|
||||
spacing: 4,
|
||||
runSpacing: 4,
|
||||
children: [
|
||||
BadgeStyles.eventStatus(event.status!),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
],
|
||||
Text(
|
||||
dateFormat.format(event.startDate),
|
||||
style: TextStyle(
|
||||
@@ -386,16 +581,21 @@ class _EventsScreenState extends State<EventsScreen> {
|
||||
style: TextStyle(
|
||||
color: isPast ? Colors.grey[500] : Colors.grey[600],
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
),
|
||||
trailing: PopupMenuButton<String>(
|
||||
key: ValueKey('event_menu_${event.id}'),
|
||||
icon: const Icon(Icons.more_vert),
|
||||
onSelected: (value) {
|
||||
if (value == 'edit') {
|
||||
_showEditEventDialog(event);
|
||||
} else if (value == 'delete') {
|
||||
_showDeleteConfirmationDialog(event);
|
||||
} else if (value == 'duplicate') {
|
||||
_duplicateEvent(event);
|
||||
}
|
||||
},
|
||||
itemBuilder: (context) => [
|
||||
@@ -409,6 +609,16 @@ class _EventsScreenState extends State<EventsScreen> {
|
||||
],
|
||||
),
|
||||
),
|
||||
const PopupMenuItem<String>(
|
||||
value: 'duplicate',
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.copy, size: 18),
|
||||
SizedBox(width: 8),
|
||||
Text('복제'),
|
||||
],
|
||||
),
|
||||
),
|
||||
const PopupMenuItem<String>(
|
||||
value: 'delete',
|
||||
child: Row(
|
||||
@@ -526,57 +736,57 @@ class _EventsScreenState extends State<EventsScreen> {
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('취소'),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () async {
|
||||
if (titleController.text.isEmpty) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('제목은 필수 입력 항목입니다')),
|
||||
);
|
||||
return;
|
||||
}
|
||||
actions: DialogActions.confirm(
|
||||
onCancel: () => Navigator.of(context).pop(),
|
||||
onConfirm: () async {
|
||||
if (titleController.text.isEmpty) {
|
||||
if (!context.mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('제목은 필수 입력 항목입니다')),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
final eventService = Provider.of<EventService>(
|
||||
context,
|
||||
listen: false,
|
||||
);
|
||||
try {
|
||||
final eventService = Provider.of<EventService>(
|
||||
context,
|
||||
listen: false,
|
||||
);
|
||||
|
||||
// 날짜와 시간 결합
|
||||
final eventDateTime = DateTime(
|
||||
selectedDate.year,
|
||||
selectedDate.month,
|
||||
selectedDate.day,
|
||||
selectedTime.hour,
|
||||
selectedTime.minute,
|
||||
);
|
||||
// 날짜와 시간 결합
|
||||
final eventDateTime = DateTime(
|
||||
selectedDate.year,
|
||||
selectedDate.month,
|
||||
selectedDate.day,
|
||||
selectedTime.hour,
|
||||
selectedTime.minute,
|
||||
);
|
||||
|
||||
await eventService.updateEvent(event.id, {
|
||||
'title': titleController.text.trim(),
|
||||
'description': descriptionController.text.trim(),
|
||||
'location': locationController.text.trim(),
|
||||
'startDate': eventDateTime.toIso8601String(),
|
||||
});
|
||||
await eventService.updateEvent(event.id, {
|
||||
'title': titleController.text.trim(),
|
||||
'description': descriptionController.text.trim().isEmpty
|
||||
? null
|
||||
: descriptionController.text.trim(),
|
||||
'location': locationController.text.trim().isEmpty
|
||||
? null
|
||||
: locationController.text.trim(),
|
||||
'startDate': eventDateTime.toIso8601String(),
|
||||
});
|
||||
|
||||
if (mounted) {
|
||||
Navigator.of(context).pop();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('이벤트가 업데이트되었습니다')),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text('이벤트 업데이트에 실패했습니다: $e')));
|
||||
}
|
||||
},
|
||||
child: const Text('저장'),
|
||||
),
|
||||
],
|
||||
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')),
|
||||
);
|
||||
}
|
||||
},
|
||||
confirmText: '저장',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -602,37 +812,30 @@ class _EventsScreenState extends State<EventsScreen> {
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('이벤트 삭제'),
|
||||
content: Text('${event.title} 이벤트를 정말 삭제하시겠습니까?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('취소'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
try {
|
||||
final eventService = Provider.of<EventService>(
|
||||
context,
|
||||
listen: false,
|
||||
);
|
||||
|
||||
await eventService.deleteEvent(event.id);
|
||||
|
||||
if (mounted) {
|
||||
Navigator.of(context).pop();
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(const SnackBar(content: Text('이벤트가 삭제되었습니다')));
|
||||
}
|
||||
} catch (e) {
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text('이벤트 삭제에 실패했습니다: $e')));
|
||||
}
|
||||
},
|
||||
style: TextButton.styleFrom(foregroundColor: Colors.red),
|
||||
child: const Text('삭제'),
|
||||
),
|
||||
],
|
||||
actions: DialogActions.confirm(
|
||||
onCancel: () => Navigator.of(context).pop(),
|
||||
onConfirm: () async {
|
||||
try {
|
||||
final eventService = Provider.of<EventService>(
|
||||
context,
|
||||
listen: false,
|
||||
);
|
||||
await eventService.deleteEvent(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: '삭제',
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -696,36 +899,56 @@ class _EventsScreenState extends State<EventsScreen> {
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
TextButton.icon(
|
||||
onPressed: () {
|
||||
// 여기서는 예시 템플릿을 제공하는 기능을 구현할 수 있습니다.
|
||||
// 현재는 안내 메시지만 표시합니다.
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('예시 템플릿 준비 중입니다.')),
|
||||
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 헤더 복사'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('닫기'),
|
||||
),
|
||||
],
|
||||
actions: DialogActions.confirm(
|
||||
onCancel: () => Navigator.of(context).pop(),
|
||||
onConfirm: () => Navigator.of(context).pop(),
|
||||
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'],
|
||||
allowedExtensions: ['xlsx', 'xls', 'csv'],
|
||||
allowMultiple: false,
|
||||
);
|
||||
|
||||
@@ -739,7 +962,7 @@ class _EventsScreenState extends State<EventsScreen> {
|
||||
final bytes = file.bytes;
|
||||
|
||||
if (bytes == null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
messenger.showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('파일을 읽을 수 없습니다. 다른 파일을 선택해주세요.'),
|
||||
duration: Duration(seconds: 3),
|
||||
@@ -749,10 +972,11 @@ class _EventsScreenState extends State<EventsScreen> {
|
||||
}
|
||||
|
||||
// 로딩 다이얼로그 표시
|
||||
if (!ctx.mounted) return;
|
||||
showDialog(
|
||||
context: context,
|
||||
context: ctx,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => AlertDialog(
|
||||
builder: (_) => AlertDialog(
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
@@ -766,17 +990,40 @@ class _EventsScreenState extends State<EventsScreen> {
|
||||
),
|
||||
);
|
||||
|
||||
// EventExcelParser를 사용하여 엑셀 파일 파싱
|
||||
final parseResult = EventExcelParser.parseExcelBytes(bytes);
|
||||
// 확장자에 따라 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.of(context).pop(); // 로딩 다이얼로그 닫기
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
// 로딩 다이얼로그 닫기 및 에러 스낵바 표시
|
||||
navigator.pop();
|
||||
messenger.showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(error),
|
||||
duration: const Duration(seconds: 4),
|
||||
@@ -786,68 +1033,58 @@ class _EventsScreenState extends State<EventsScreen> {
|
||||
}
|
||||
|
||||
// 로딩 다이얼로그 업데이트
|
||||
if (mounted) {
|
||||
Navigator.of(context).pop();
|
||||
showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => AlertDialog(
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const CircularProgressIndicator(),
|
||||
const SizedBox(height: 16),
|
||||
Text('이벤트 ${events.length}개 생성 중...'),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
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 eventService = Provider.of<EventService>(context, listen: false);
|
||||
// 이벤트 서비스를 통해 이벤트 생성 (비동기 이전에 캡처해 둔 것을 사용)
|
||||
final results = await eventService.createEventsFromFile(events);
|
||||
|
||||
// 로딩 다이얼로그 닫기
|
||||
if (mounted) Navigator.of(context).pop();
|
||||
if (navigator.canPop()) navigator.pop();
|
||||
|
||||
// 결과 표시
|
||||
if (mounted) {
|
||||
// 상세 결과 다이얼로그 표시
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: const Text('파일 처리 결과'),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('파일명: $fileName'),
|
||||
const SizedBox(height: 8),
|
||||
Text('처리된 행: $processedRows개'),
|
||||
Text('생성된 이벤트: ${results.length}개'),
|
||||
if (invalidRows > 0) Text('유효하지 않은 행: $invalidRows개'),
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
// 이벤트 목록 새로고침
|
||||
_loadEvents();
|
||||
},
|
||||
child: const Text('확인'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
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();
|
||||
_loadEvents();
|
||||
},
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
// 로딩 다이얼로그가 열려 있으면 닫기
|
||||
if (mounted) Navigator.of(context).pop();
|
||||
if (navigator.canPop()) navigator.pop();
|
||||
|
||||
// 사용자 친화적인 오류 메시지 표시
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
// 사용자 친화적인 오류 메시지 표시 (messenger는 사전 캡처되어 context 불필요)
|
||||
messenger.showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('파일 처리 중 오류가 발생했습니다: $e'),
|
||||
duration: const Duration(seconds: 4),
|
||||
|
||||
Reference in New Issue
Block a user