214 lines
7.0 KiB
Dart
214 lines
7.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:flutter_animate/flutter_animate.dart';
|
|
import '../providers/event_provider.dart';
|
|
import '../theme.dart';
|
|
import '../l10n/app_localizations.dart';
|
|
import '../widgets/skeleton.dart';
|
|
|
|
class EventListPage extends ConsumerStatefulWidget {
|
|
const EventListPage({super.key});
|
|
|
|
@override
|
|
ConsumerState<EventListPage> createState() => _EventListPageState();
|
|
}
|
|
|
|
class _EventListPageState extends ConsumerState<EventListPage> {
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
Future.microtask(() {
|
|
ref.read(eventProvider.notifier).loadEvents();
|
|
});
|
|
}
|
|
|
|
String _formatDate(DateTime date) {
|
|
return '${date.month}/${date.day} ${date.hour.toString().padLeft(2, '0')}:${date.minute.toString().padLeft(2, '0')}';
|
|
}
|
|
|
|
Color _getStatusColor(String status) {
|
|
switch (status) {
|
|
case 'published':
|
|
return AppColors.success;
|
|
case 'draft':
|
|
return AppColors.warning;
|
|
case 'expired':
|
|
return AppColors.textTertiary;
|
|
default:
|
|
return AppColors.primary;
|
|
}
|
|
}
|
|
|
|
String _getStatusText(String status, AppLocalizations l10n) {
|
|
switch (status) {
|
|
case 'published':
|
|
return l10n.published;
|
|
case 'draft':
|
|
return l10n.draft;
|
|
case 'expired':
|
|
return l10n.expired;
|
|
default:
|
|
return status;
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final l10n = AppLocalizations.of(context)!;
|
|
final eventState = ref.watch(eventProvider);
|
|
|
|
return Scaffold(
|
|
backgroundColor: AppColors.background,
|
|
appBar: AppBar(
|
|
title: Text(l10n.eventRecords),
|
|
),
|
|
body: eventState.isLoading
|
|
? SkeletonList(
|
|
count: 5,
|
|
itemBuilder: (_) => const EventCardSkeleton(),
|
|
)
|
|
: eventState.events.isEmpty
|
|
? _buildEmptyState(l10n)
|
|
: ListView.builder(
|
|
padding: const EdgeInsets.all(16),
|
|
itemCount: eventState.events.length,
|
|
itemBuilder: (context, index) {
|
|
final event = eventState.events[index];
|
|
return _buildEventCard(event, index, l10n);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildEmptyState(AppLocalizations l10n) {
|
|
return Center(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Icon(
|
|
Icons.event_note_outlined,
|
|
size: 64,
|
|
color: AppColors.textTertiary.withOpacity(0.5),
|
|
),
|
|
const SizedBox(height: 16),
|
|
Text(
|
|
l10n.noEvents,
|
|
style: TextStyle(fontSize: 16, color: AppColors.textSecondary),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildEventCard(event, int index, AppLocalizations l10n) {
|
|
return Container(
|
|
margin: const EdgeInsets.only(bottom: 12),
|
|
decoration: BoxDecoration(
|
|
color: AppColors.surface,
|
|
borderRadius: BorderRadius.circular(16),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.black.withOpacity(0.03),
|
|
blurRadius: 10,
|
|
offset: const Offset(0, 2),
|
|
),
|
|
],
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Container(
|
|
width: 44,
|
|
height: 44,
|
|
decoration: BoxDecoration(
|
|
gradient: AppGradients.primary,
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
child: const Icon(Icons.event, color: Colors.white, size: 22),
|
|
),
|
|
const SizedBox(width: 12),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Expanded(
|
|
child: Text(
|
|
event.entityName,
|
|
style: TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w600,
|
|
color: AppColors.textPrimary,
|
|
),
|
|
),
|
|
),
|
|
Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
|
decoration: BoxDecoration(
|
|
color: _getStatusColor(event.status).withOpacity(0.1),
|
|
borderRadius: BorderRadius.circular(20),
|
|
),
|
|
child: Text(
|
|
_getStatusText(event.status, l10n),
|
|
style: TextStyle(
|
|
fontSize: 11,
|
|
fontWeight: FontWeight.w500,
|
|
color: _getStatusColor(event.status),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 6),
|
|
Text(
|
|
event.description,
|
|
maxLines: 2,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: TextStyle(
|
|
fontSize: 14,
|
|
color: AppColors.textSecondary,
|
|
height: 1.4,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const Divider(height: 1, indent: 16, endIndent: 16),
|
|
Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
|
child: Row(
|
|
children: [
|
|
Icon(Icons.access_time, size: 14, color: AppColors.textTertiary),
|
|
const SizedBox(width: 4),
|
|
Text(
|
|
'${l10n.publishTime}: ${_formatDate(event.publishTime)}',
|
|
style: TextStyle(fontSize: 12, color: AppColors.textTertiary),
|
|
),
|
|
if (event.popupReminder) ...[
|
|
const SizedBox(width: 12),
|
|
Icon(Icons.notifications_active, size: 14, color: AppColors.warning),
|
|
],
|
|
const Spacer(),
|
|
if (event.creatorName != null)
|
|
Text(
|
|
event.creatorName!,
|
|
style: TextStyle(fontSize: 12, color: AppColors.textTertiary),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
).animate().fadeIn(duration: 300.ms, delay: (index * 50).ms).slideY(begin: 0.1, end: 0, duration: 300.ms);
|
|
}
|
|
}
|