Add admin management tabs and TV/mobile fixes
This commit is contained in:
@@ -3,9 +3,13 @@ import 'package:provider/provider.dart';
|
||||
import '../../models/bible_verse.dart';
|
||||
import '../../models/family_member.dart';
|
||||
import '../../models/photo.dart';
|
||||
import '../../models/announcement.dart';
|
||||
import '../../models/schedule_item.dart';
|
||||
import '../../services/bible_verse_service.dart';
|
||||
import '../../services/family_service.dart';
|
||||
import '../../services/photo_service.dart';
|
||||
import '../../services/announcement_service.dart';
|
||||
import '../../services/schedule_service.dart';
|
||||
|
||||
class AdminScreen extends StatefulWidget {
|
||||
const AdminScreen({super.key});
|
||||
@@ -18,15 +22,18 @@ class _AdminScreenState extends State<AdminScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return DefaultTabController(
|
||||
length: 3,
|
||||
length: 5,
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Admin Settings'),
|
||||
bottom: const TabBar(
|
||||
isScrollable: true,
|
||||
tabs: [
|
||||
Tab(text: 'Family Members'),
|
||||
Tab(text: 'Photos'),
|
||||
Tab(text: 'Bible Verses'),
|
||||
Tab(text: 'Announcements'),
|
||||
Tab(text: 'Schedules'),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -35,6 +42,8 @@ class _AdminScreenState extends State<AdminScreen> {
|
||||
FamilyManagerTab(),
|
||||
PhotoManagerTab(),
|
||||
BibleVerseManagerTab(),
|
||||
AnnouncementManagerTab(),
|
||||
ScheduleManagerTab(),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -448,3 +457,344 @@ class _BibleVerseManagerTabState extends State<BibleVerseManagerTab> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class AnnouncementManagerTab extends StatefulWidget {
|
||||
const AnnouncementManagerTab({super.key});
|
||||
|
||||
@override
|
||||
State<AnnouncementManagerTab> createState() => _AnnouncementManagerTabState();
|
||||
}
|
||||
|
||||
class _AnnouncementManagerTabState extends State<AnnouncementManagerTab> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: () => _showAddAnnouncementDialog(context),
|
||||
child: const Icon(Icons.campaign),
|
||||
),
|
||||
body: FutureBuilder<List<Announcement>>(
|
||||
future: Provider.of<AnnouncementService>(context).fetchAnnouncements(),
|
||||
builder: (context, snapshot) {
|
||||
if (!snapshot.hasData) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
final announcements = snapshot.data!;
|
||||
if (announcements.isEmpty) {
|
||||
return const Center(
|
||||
child: Text(
|
||||
'No announcements added yet',
|
||||
style: TextStyle(color: Colors.grey),
|
||||
),
|
||||
);
|
||||
}
|
||||
return ListView.builder(
|
||||
itemCount: announcements.length,
|
||||
itemBuilder: (context, index) {
|
||||
final announcement = announcements[index];
|
||||
return ListTile(
|
||||
title: Text(announcement.title),
|
||||
subtitle: Text(
|
||||
announcement.content,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
trailing: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (announcement.priority > 0)
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.orangeAccent,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Text(
|
||||
'P${announcement.priority}',
|
||||
style: const TextStyle(
|
||||
color: Colors.white, fontSize: 10),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Icon(
|
||||
announcement.active ? Icons.check_circle : Icons.cancel,
|
||||
color: announcement.active ? Colors.green : Colors.grey,
|
||||
size: 16,
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.delete, color: Colors.red),
|
||||
onPressed: () async {
|
||||
await Provider.of<AnnouncementService>(
|
||||
context,
|
||||
listen: false,
|
||||
).deleteAnnouncement(announcement.id);
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showAddAnnouncementDialog(BuildContext context) {
|
||||
final titleController = TextEditingController();
|
||||
final contentController = TextEditingController();
|
||||
final priorityController = TextEditingController(text: '0');
|
||||
bool isActive = true;
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => StatefulBuilder(
|
||||
builder: (context, setDialogState) => AlertDialog(
|
||||
title: const Text('Add Announcement'),
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
TextField(
|
||||
controller: titleController,
|
||||
decoration: const InputDecoration(labelText: 'Title'),
|
||||
),
|
||||
TextField(
|
||||
controller: contentController,
|
||||
decoration: const InputDecoration(labelText: 'Content'),
|
||||
maxLines: 3,
|
||||
),
|
||||
TextField(
|
||||
controller: priorityController,
|
||||
decoration:
|
||||
const InputDecoration(labelText: 'Priority (0-10)'),
|
||||
keyboardType: TextInputType.number,
|
||||
),
|
||||
SwitchListTile(
|
||||
title: const Text('Active'),
|
||||
value: isActive,
|
||||
onChanged: (value) {
|
||||
setDialogState(() {
|
||||
isActive = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
if (titleController.text.isNotEmpty) {
|
||||
await Provider.of<AnnouncementService>(
|
||||
context,
|
||||
listen: false,
|
||||
).createAnnouncement(
|
||||
Announcement(
|
||||
id: '',
|
||||
title: titleController.text,
|
||||
content: contentController.text,
|
||||
priority: int.tryParse(priorityController.text) ?? 0,
|
||||
active: isActive,
|
||||
),
|
||||
);
|
||||
if (mounted) {
|
||||
Navigator.pop(context);
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
},
|
||||
child: const Text('Add'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class ScheduleManagerTab extends StatefulWidget {
|
||||
const ScheduleManagerTab({super.key});
|
||||
|
||||
@override
|
||||
State<ScheduleManagerTab> createState() => _ScheduleManagerTabState();
|
||||
}
|
||||
|
||||
class _ScheduleManagerTabState extends State<ScheduleManagerTab> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: () => _showAddScheduleDialog(context),
|
||||
child: const Icon(Icons.calendar_today),
|
||||
),
|
||||
body: FutureBuilder<List<ScheduleItem>>(
|
||||
future: Provider.of<ScheduleService>(context).fetchSchedules(),
|
||||
builder: (context, snapshot) {
|
||||
if (!snapshot.hasData) {
|
||||
return const Center(child: CircularProgressIndicator());
|
||||
}
|
||||
final schedules = snapshot.data!;
|
||||
if (schedules.isEmpty) {
|
||||
return const Center(
|
||||
child: Text(
|
||||
'No schedules added yet',
|
||||
style: TextStyle(color: Colors.grey),
|
||||
),
|
||||
);
|
||||
}
|
||||
return ListView.builder(
|
||||
itemCount: schedules.length,
|
||||
itemBuilder: (context, index) {
|
||||
final schedule = schedules[index];
|
||||
return ListTile(
|
||||
title: Text(schedule.title),
|
||||
subtitle: Text(
|
||||
'${schedule.description}\n${schedule.startDate.toIso8601String().split('T')[0]} ~ ${schedule.endDate.toIso8601String().split('T')[0]}',
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
isThreeLine: true,
|
||||
trailing: IconButton(
|
||||
icon: const Icon(Icons.delete, color: Colors.red),
|
||||
onPressed: () async {
|
||||
await Provider.of<ScheduleService>(
|
||||
context,
|
||||
listen: false,
|
||||
).deleteSchedule(schedule.id);
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _showAddScheduleDialog(BuildContext context) {
|
||||
final titleController = TextEditingController();
|
||||
final descriptionController = TextEditingController();
|
||||
final startController = TextEditingController(
|
||||
text: DateTime.now().toIso8601String().split('T')[0],
|
||||
);
|
||||
final endController = TextEditingController(
|
||||
text: DateTime.now().toIso8601String().split('T')[0],
|
||||
);
|
||||
bool isAllDay = true;
|
||||
String? selectedFamilyMemberId;
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => StatefulBuilder(
|
||||
builder: (context, setDialogState) => AlertDialog(
|
||||
title: const Text('Add Schedule'),
|
||||
content: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
TextField(
|
||||
controller: titleController,
|
||||
decoration: const InputDecoration(labelText: 'Title'),
|
||||
),
|
||||
TextField(
|
||||
controller: descriptionController,
|
||||
decoration: const InputDecoration(labelText: 'Description'),
|
||||
),
|
||||
TextField(
|
||||
controller: startController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Start Date (YYYY-MM-DD)',
|
||||
),
|
||||
),
|
||||
TextField(
|
||||
controller: endController,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'End Date (YYYY-MM-DD)',
|
||||
),
|
||||
),
|
||||
SwitchListTile(
|
||||
title: const Text('All Day'),
|
||||
value: isAllDay,
|
||||
onChanged: (value) {
|
||||
setDialogState(() {
|
||||
isAllDay = value;
|
||||
});
|
||||
},
|
||||
),
|
||||
FutureBuilder<List<FamilyMember>>(
|
||||
future: Provider.of<FamilyService>(context, listen: false)
|
||||
.fetchFamilyMembers(),
|
||||
builder: (context, snapshot) {
|
||||
if (!snapshot.hasData) return const SizedBox();
|
||||
final members = snapshot.data!;
|
||||
return DropdownButtonFormField<String>(
|
||||
value: selectedFamilyMemberId,
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Family Member',
|
||||
),
|
||||
items: members.map((member) {
|
||||
return DropdownMenuItem(
|
||||
value: member.id,
|
||||
child: Text(member.name),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (value) {
|
||||
setDialogState(() {
|
||||
selectedFamilyMemberId = value;
|
||||
});
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
if (titleController.text.isNotEmpty) {
|
||||
final startDate =
|
||||
DateTime.tryParse(startController.text) ?? DateTime.now();
|
||||
final endDate =
|
||||
DateTime.tryParse(endController.text) ?? DateTime.now();
|
||||
|
||||
await Provider.of<ScheduleService>(
|
||||
context,
|
||||
listen: false,
|
||||
).createSchedule(
|
||||
ScheduleItem(
|
||||
id: '',
|
||||
title: titleController.text,
|
||||
description: descriptionController.text,
|
||||
startDate: startDate,
|
||||
endDate: endDate,
|
||||
familyMemberId: selectedFamilyMemberId ?? '',
|
||||
isAllDay: isAllDay,
|
||||
),
|
||||
);
|
||||
if (mounted) {
|
||||
Navigator.pop(context);
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
},
|
||||
child: const Text('Add'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
@@ -47,84 +48,102 @@ class _TvDashboardScreenState extends State<TvDashboardScreen> {
|
||||
Widget build(BuildContext context) {
|
||||
// 1920x1080 reference
|
||||
return Scaffold(
|
||||
body: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(32.0), // Outer margin safe zone
|
||||
child: Column(
|
||||
children: [
|
||||
// Header: Time and Weather
|
||||
SizedBox(
|
||||
height: 100,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [const DigitalClockWidget(), const WeatherWidget()],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
// Main Content Grid
|
||||
Expanded(
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
body: Center(
|
||||
child: AspectRatio(
|
||||
aspectRatio: 16 / 9,
|
||||
child: FittedBox(
|
||||
fit: BoxFit.contain,
|
||||
child: SizedBox(
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(32.0), // Outer margin safe zone
|
||||
child: Column(
|
||||
children: [
|
||||
// Left Column: Calendar, Schedule, Announcement
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: Column(
|
||||
// Header: Time and Weather
|
||||
SizedBox(
|
||||
height: 100,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Expanded(flex: 4, child: CalendarWidget()),
|
||||
const SizedBox(height: 16),
|
||||
const Expanded(flex: 4, child: ScheduleListWidget()),
|
||||
const SizedBox(height: 16),
|
||||
const Expanded(flex: 2, child: AnnouncementWidget()),
|
||||
const DigitalClockWidget(),
|
||||
const WeatherWidget()
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 24),
|
||||
// Center Column: Photo Slideshow
|
||||
const SizedBox(height: 24),
|
||||
// Main Content Grid
|
||||
Expanded(
|
||||
flex: 4,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.5),
|
||||
blurRadius: 20,
|
||||
offset: const Offset(0, 10),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Left Column: Calendar, Schedule, Announcement
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: Column(
|
||||
children: [
|
||||
const Expanded(
|
||||
flex: 4, child: CalendarWidget()),
|
||||
const SizedBox(height: 16),
|
||||
const Expanded(
|
||||
flex: 4, child: ScheduleListWidget()),
|
||||
const SizedBox(height: 16),
|
||||
const Expanded(
|
||||
flex: 2, child: AnnouncementWidget()),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: const PhotoSlideshowWidget(),
|
||||
),
|
||||
const SizedBox(width: 24),
|
||||
// Center Column: Photo Slideshow
|
||||
Expanded(
|
||||
flex: 4,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.5),
|
||||
blurRadius: 20,
|
||||
offset: const Offset(0, 10),
|
||||
),
|
||||
],
|
||||
),
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: const PhotoSlideshowWidget(),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 24),
|
||||
// Right Column: Todos, Bible Verse
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: Column(
|
||||
children: [
|
||||
const Expanded(
|
||||
flex: 6, child: TodoListWidget()),
|
||||
const SizedBox(height: 16),
|
||||
const Expanded(
|
||||
flex: 3, child: BibleVerseWidget()),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 24),
|
||||
// Right Column: Todos, Bible Verse
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: Column(
|
||||
children: [
|
||||
const Expanded(flex: 6, child: TodoListWidget()),
|
||||
const SizedBox(height: 16),
|
||||
const Expanded(flex: 3, child: BibleVerseWidget()),
|
||||
],
|
||||
// Hidden trigger for admin/mobile view (e.g. long press corner)
|
||||
GestureDetector(
|
||||
onLongPress: () {
|
||||
Navigator.of(context).pushNamed('/admin');
|
||||
},
|
||||
child: Container(
|
||||
width: 50,
|
||||
height: 50,
|
||||
color: Colors.transparent,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
// Hidden trigger for admin/mobile view (e.g. long press corner)
|
||||
GestureDetector(
|
||||
onLongPress: () {
|
||||
Navigator.of(context).pushNamed('/admin');
|
||||
},
|
||||
child: Container(
|
||||
width: 50,
|
||||
height: 50,
|
||||
color: Colors.transparent,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user