Eliminar creche_app/lib/features/diary/diary_history_screen.dart
This commit is contained in:
parent
9886113361
commit
0ec2797511
|
|
@ -1,258 +0,0 @@
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:supabase_flutter/supabase_flutter.dart';
|
|
||||||
import 'package:table_calendar/table_calendar.dart';
|
|
||||||
import 'package:intl/intl.dart';
|
|
||||||
import '/models/daily_diary.dart';
|
|
||||||
|
|
||||||
class DiaryHistoryScreen extends ConsumerStatefulWidget {
|
|
||||||
final String childId;
|
|
||||||
const DiaryHistoryScreen({super.key, required this.childId});
|
|
||||||
|
|
||||||
@override
|
|
||||||
ConsumerState<DiaryHistoryScreen> createState() =>
|
|
||||||
_DiaryHistoryScreenState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _DiaryHistoryScreenState extends ConsumerState<DiaryHistoryScreen> {
|
|
||||||
DateTime _focusedDay = DateTime.now();
|
|
||||||
DateTime? _selectedDay;
|
|
||||||
|
|
||||||
String _moodEmoji(String? mood) {
|
|
||||||
switch (mood) {
|
|
||||||
case 'happy': return '😊';
|
|
||||||
case 'normal': return '😐';
|
|
||||||
case 'sad': return '😟';
|
|
||||||
case 'sick': return '🤒';
|
|
||||||
case 'excited': return '😃';
|
|
||||||
default: return '😐';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
final supabase = Supabase.instance.client;
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: const Color(0xFF1A1A2E),
|
|
||||||
appBar: AppBar(
|
|
||||||
backgroundColor: const Color(0xFF16213E),
|
|
||||||
title: const Text('Histórico do Diário',
|
|
||||||
style: TextStyle(color: Color(0xFF4FC3F7))),
|
|
||||||
),
|
|
||||||
body: Column(
|
|
||||||
children: [
|
|
||||||
// Calendário
|
|
||||||
Container(
|
|
||||||
color: const Color(0xFF16213E),
|
|
||||||
child: TableCalendar(
|
|
||||||
firstDay: DateTime.now().subtract(const Duration(days: 365)),
|
|
||||||
lastDay: DateTime.now(),
|
|
||||||
focusedDay: _focusedDay,
|
|
||||||
selectedDayPredicate: (day) => isSameDay(_selectedDay, day),
|
|
||||||
onDaySelected: (selected, focused) {
|
|
||||||
setState(() {
|
|
||||||
_selectedDay = selected;
|
|
||||||
_focusedDay = focused;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
calendarStyle: const CalendarStyle(
|
|
||||||
defaultTextStyle: TextStyle(color: Colors.white),
|
|
||||||
weekendTextStyle: TextStyle(color: Color(0xFF4FC3F7)),
|
|
||||||
selectedDecoration: BoxDecoration(
|
|
||||||
color: Color(0xFF4FC3F7),
|
|
||||||
shape: BoxShape.circle,
|
|
||||||
),
|
|
||||||
todayDecoration: BoxDecoration(
|
|
||||||
color: Color(0xFF333366),
|
|
||||||
shape: BoxShape.circle,
|
|
||||||
),
|
|
||||||
outsideDaysVisible: false,
|
|
||||||
),
|
|
||||||
headerStyle: const HeaderStyle(
|
|
||||||
formatButtonVisible: false,
|
|
||||||
titleCentered: true,
|
|
||||||
titleTextStyle: TextStyle(color: Colors.white, fontSize: 16),
|
|
||||||
leftChevronIcon:
|
|
||||||
Icon(Icons.chevron_left, color: Color(0xFF4FC3F7)),
|
|
||||||
rightChevronIcon:
|
|
||||||
Icon(Icons.chevron_right, color: Color(0xFF4FC3F7)),
|
|
||||||
),
|
|
||||||
daysOfWeekStyle: const DaysOfWeekStyle(
|
|
||||||
weekdayStyle: TextStyle(color: Color(0xFF888888)),
|
|
||||||
weekendStyle: TextStyle(color: Color(0xFF4FC3F7)),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
|
|
||||||
// Lista de diários
|
|
||||||
Expanded(
|
|
||||||
child: StreamBuilder<List<Map<String, dynamic>>>(
|
|
||||||
stream: supabase
|
|
||||||
.from('daily_diaries')
|
|
||||||
.stream(primaryKey: ['id']).eq('child_id', widget.childId),
|
|
||||||
builder: (context, snapshot) {
|
|
||||||
if (!snapshot.hasData) {
|
|
||||||
return const Center(
|
|
||||||
child: CircularProgressIndicator(
|
|
||||||
color: Color(0xFF4FC3F7)));
|
|
||||||
}
|
|
||||||
|
|
||||||
var diaries =
|
|
||||||
snapshot.data!.map(DailyDiary.fromMap).toList()
|
|
||||||
..sort((a, b) => b.date.compareTo(a.date));
|
|
||||||
|
|
||||||
if (_selectedDay != null) {
|
|
||||||
diaries = diaries
|
|
||||||
.where((d) => isSameDay(d.date, _selectedDay))
|
|
||||||
.toList();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (diaries.isEmpty) {
|
|
||||||
return const Center(
|
|
||||||
child: Column(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
Icon(Icons.book_outlined,
|
|
||||||
size: 60, color: Color(0xFF333366)),
|
|
||||||
SizedBox(height: 12),
|
|
||||||
Text('Sem diários neste dia.',
|
|
||||||
style: TextStyle(color: Color(0xFF888888))),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ListView.builder(
|
|
||||||
padding: const EdgeInsets.all(16),
|
|
||||||
itemCount: diaries.length,
|
|
||||||
itemBuilder: (context, i) {
|
|
||||||
final diary = diaries[i];
|
|
||||||
return _DiaryCard(diary: diary, moodEmoji: _moodEmoji);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class _DiaryCard extends StatelessWidget {
|
|
||||||
final DailyDiary diary;
|
|
||||||
final String Function(String?) moodEmoji;
|
|
||||||
const _DiaryCard({required this.diary, required this.moodEmoji});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Container(
|
|
||||||
margin: const EdgeInsets.only(bottom: 14),
|
|
||||||
padding: const EdgeInsets.all(16),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: const Color(0xFF16213E),
|
|
||||||
borderRadius: BorderRadius.circular(16),
|
|
||||||
border: Border.all(color: const Color(0xFF333366)),
|
|
||||||
),
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
// Header: data + humor
|
|
||||||
Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
DateFormat('d MMMM yyyy', 'pt_PT').format(diary.date),
|
|
||||||
style: const TextStyle(
|
|
||||||
color: Color(0xFF4FC3F7),
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
fontSize: 15),
|
|
||||||
),
|
|
||||||
Text(moodEmoji(diary.mood),
|
|
||||||
style: const TextStyle(fontSize: 28)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const Divider(color: Color(0xFF333366), height: 16),
|
|
||||||
|
|
||||||
// Alimentação
|
|
||||||
if (diary.food != null && diary.food!.isNotEmpty)
|
|
||||||
_InfoRow(icon: Icons.restaurant, label: 'Alimentação', value: diary.food!),
|
|
||||||
|
|
||||||
// Sono
|
|
||||||
if (diary.sleepMinutes != null && diary.sleepMinutes! > 0)
|
|
||||||
_InfoRow(
|
|
||||||
icon: Icons.bedtime,
|
|
||||||
label: 'Sono',
|
|
||||||
value:
|
|
||||||
'${diary.sleepMinutes! ~/ 60}h ${diary.sleepMinutes! % 60}min',
|
|
||||||
),
|
|
||||||
|
|
||||||
// Atividades
|
|
||||||
if (diary.activities != null && diary.activities!.isNotEmpty)
|
|
||||||
_InfoRow(
|
|
||||||
icon: Icons.sports_esports,
|
|
||||||
label: 'Atividades',
|
|
||||||
value: diary.activities!),
|
|
||||||
|
|
||||||
// Notas
|
|
||||||
if (diary.notes != null && diary.notes!.isNotEmpty)
|
|
||||||
_InfoRow(
|
|
||||||
icon: Icons.note,
|
|
||||||
label: 'Notas',
|
|
||||||
value: diary.notes!),
|
|
||||||
|
|
||||||
// Fotos
|
|
||||||
if (diary.photos.isNotEmpty) ...[
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
SizedBox(
|
|
||||||
height: 80,
|
|
||||||
child: ListView.builder(
|
|
||||||
scrollDirection: Axis.horizontal,
|
|
||||||
itemCount: diary.photos.length,
|
|
||||||
itemBuilder: (context, i) => Padding(
|
|
||||||
padding: const EdgeInsets.only(right: 8),
|
|
||||||
child: ClipRRect(
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
|
||||||
child: Image.network(diary.photos[i],
|
|
||||||
width: 80, height: 80, fit: BoxFit.cover),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class _InfoRow extends StatelessWidget {
|
|
||||||
final IconData icon;
|
|
||||||
final String label;
|
|
||||||
final String value;
|
|
||||||
const _InfoRow(
|
|
||||||
{required this.icon, required this.label, required this.value});
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.only(bottom: 8),
|
|
||||||
child: Row(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Icon(icon, size: 16, color: const Color(0xFF4FC3F7)),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
Text('$label: ',
|
|
||||||
style: const TextStyle(
|
|
||||||
color: Color(0xFF888888),
|
|
||||||
fontSize: 13,
|
|
||||||
fontWeight: FontWeight.w500)),
|
|
||||||
Expanded(
|
|
||||||
child: Text(value,
|
|
||||||
style: const TextStyle(color: Colors.white, fontSize: 13))),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue