Eliminar creche_app/lib/features/children/children_list_screen.dart
This commit is contained in:
parent
5434959e20
commit
9886113361
|
|
@ -1,241 +0,0 @@
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
||||||
import 'package:go_router/go_router.dart';
|
|
||||||
import '/core/supabase_client.dart';
|
|
||||||
import '/models/child.dart';
|
|
||||||
|
|
||||||
class ChildrenListScreen extends ConsumerStatefulWidget {
|
|
||||||
const ChildrenListScreen({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
ConsumerState<ChildrenListScreen> createState() => _ChildrenListScreenState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _ChildrenListScreenState extends ConsumerState<ChildrenListScreen> {
|
|
||||||
String _searchQuery = '';
|
|
||||||
String? _selectedClass;
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: const Color(0xFF1A1A2E),
|
|
||||||
appBar: AppBar(
|
|
||||||
backgroundColor: const Color(0xFF16213E),
|
|
||||||
title: const Text('Lista de Crianças',
|
|
||||||
style: TextStyle(color: Color(0xFF4FC3F7))),
|
|
||||||
actions: [
|
|
||||||
IconButton(
|
|
||||||
icon: const Icon(Icons.add, color: Color(0xFF4FC3F7)),
|
|
||||||
onPressed: () => context.go('/child/new'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
body: Column(
|
|
||||||
children: [
|
|
||||||
// Barra de pesquisa + filtro
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.all(12),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: TextField(
|
|
||||||
onChanged: (v) =>
|
|
||||||
setState(() => _searchQuery = v.toLowerCase()),
|
|
||||||
style: const TextStyle(color: Colors.white),
|
|
||||||
decoration: InputDecoration(
|
|
||||||
hintText: 'Buscar por nome...',
|
|
||||||
hintStyle: const TextStyle(color: Color(0xFF888888)),
|
|
||||||
prefixIcon: const Icon(Icons.search,
|
|
||||||
color: Color(0xFF4FC3F7)),
|
|
||||||
filled: true,
|
|
||||||
fillColor: const Color(0xFF16213E),
|
|
||||||
enabledBorder: OutlineInputBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
borderSide:
|
|
||||||
const BorderSide(color: Color(0xFF333366)),
|
|
||||||
),
|
|
||||||
focusedBorder: OutlineInputBorder(
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
borderSide: const BorderSide(
|
|
||||||
color: Color(0xFF4FC3F7), width: 2),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(width: 8),
|
|
||||||
Container(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 8),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: const Color(0xFF16213E),
|
|
||||||
borderRadius: BorderRadius.circular(12),
|
|
||||||
border: Border.all(color: const Color(0xFF333366)),
|
|
||||||
),
|
|
||||||
child: DropdownButton<String>(
|
|
||||||
hint: const Text('Turma',
|
|
||||||
style: TextStyle(color: Color(0xFF888888))),
|
|
||||||
value: _selectedClass,
|
|
||||||
dropdownColor: const Color(0xFF16213E),
|
|
||||||
style: const TextStyle(color: Colors.white),
|
|
||||||
underline: const SizedBox(),
|
|
||||||
items: const [
|
|
||||||
DropdownMenuItem(
|
|
||||||
value: null,
|
|
||||||
child: Text('Todas',
|
|
||||||
style: TextStyle(color: Color(0xFF888888)))),
|
|
||||||
DropdownMenuItem(
|
|
||||||
value: 'bercario1', child: Text('Berçário 1')),
|
|
||||||
DropdownMenuItem(
|
|
||||||
value: 'jardim2', child: Text('Jardim 2')),
|
|
||||||
],
|
|
||||||
onChanged: (v) => setState(() => _selectedClass = v),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
|
|
||||||
// Lista de crianças via stream
|
|
||||||
Expanded(
|
|
||||||
child: StreamBuilder<List<Map<String, dynamic>>>(
|
|
||||||
stream: ref
|
|
||||||
.read(supabaseProvider)
|
|
||||||
.from('children')
|
|
||||||
.stream(primaryKey: ['id']),
|
|
||||||
builder: (context, snapshot) {
|
|
||||||
if (snapshot.hasError) {
|
|
||||||
return Center(
|
|
||||||
child: Text('Erro: ${snapshot.error}',
|
|
||||||
style: const TextStyle(color: Colors.red)));
|
|
||||||
}
|
|
||||||
if (!snapshot.hasData) {
|
|
||||||
return const Center(
|
|
||||||
child: CircularProgressIndicator(
|
|
||||||
color: Color(0xFF4FC3F7)));
|
|
||||||
}
|
|
||||||
|
|
||||||
final children = snapshot.data!
|
|
||||||
.map(Child.fromMap)
|
|
||||||
.where((c) =>
|
|
||||||
c.fullName.toLowerCase().contains(_searchQuery) &&
|
|
||||||
(_selectedClass == null ||
|
|
||||||
c.classId == _selectedClass))
|
|
||||||
.toList();
|
|
||||||
|
|
||||||
if (children.isEmpty) {
|
|
||||||
return const Center(
|
|
||||||
child: Column(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
Icon(Icons.child_care,
|
|
||||||
size: 64, color: Color(0xFF333366)),
|
|
||||||
SizedBox(height: 16),
|
|
||||||
Text('Nenhuma criança encontrada',
|
|
||||||
style: TextStyle(color: Color(0xFF888888))),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ListView.builder(
|
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
|
||||||
itemCount: children.length,
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
final child = children[index];
|
|
||||||
return _ChildListCard(
|
|
||||||
child: child,
|
|
||||||
onTap: () => context.go('/child/${child.id}'),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class _ChildListCard extends StatelessWidget {
|
|
||||||
final Child child;
|
|
||||||
final VoidCallback onTap;
|
|
||||||
const _ChildListCard({required this.child, required this.onTap});
|
|
||||||
|
|
||||||
String get _moodEmoji {
|
|
||||||
switch (child.mood) {
|
|
||||||
case 'happy': return '😊';
|
|
||||||
case 'sad': return '😟';
|
|
||||||
case 'sick': return '🤒';
|
|
||||||
case 'excited': return '😃';
|
|
||||||
default: return '😐';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return GestureDetector(
|
|
||||||
onTap: onTap,
|
|
||||||
child: Container(
|
|
||||||
margin: const EdgeInsets.only(bottom: 10),
|
|
||||||
padding: const EdgeInsets.all(14),
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: const Color(0xFF16213E),
|
|
||||||
borderRadius: BorderRadius.circular(16),
|
|
||||||
border: Border.all(color: const Color(0xFF333366)),
|
|
||||||
),
|
|
||||||
child: Row(
|
|
||||||
children: [
|
|
||||||
// Avatar
|
|
||||||
CircleAvatar(
|
|
||||||
radius: 30,
|
|
||||||
backgroundImage: child.photoUrl != null
|
|
||||||
? NetworkImage(child.photoUrl!)
|
|
||||||
: null,
|
|
||||||
backgroundColor: const Color(0xFF4FC3F7).withOpacity(0.2),
|
|
||||||
child: child.photoUrl == null
|
|
||||||
? const Icon(Icons.child_care,
|
|
||||||
color: Color(0xFF4FC3F7), size: 30)
|
|
||||||
: null,
|
|
||||||
),
|
|
||||||
const SizedBox(width: 14),
|
|
||||||
// Info
|
|
||||||
Expanded(
|
|
||||||
child: Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
Text(child.fullName,
|
|
||||||
style: const TextStyle(
|
|
||||||
color: Colors.white,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
fontSize: 15)),
|
|
||||||
const SizedBox(height: 4),
|
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
const Icon(Icons.cake,
|
|
||||||
size: 12, color: Color(0xFF888888)),
|
|
||||||
const SizedBox(width: 4),
|
|
||||||
Text('${child.age} anos',
|
|
||||||
style: const TextStyle(
|
|
||||||
color: Color(0xFF888888), fontSize: 12)),
|
|
||||||
const SizedBox(width: 12),
|
|
||||||
const Icon(Icons.school,
|
|
||||||
size: 12, color: Color(0xFF888888)),
|
|
||||||
const SizedBox(width: 4),
|
|
||||||
Text(child.classId,
|
|
||||||
style: const TextStyle(
|
|
||||||
color: Color(0xFF888888), fontSize: 12)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
// Emoji humor
|
|
||||||
Text(_moodEmoji, style: const TextStyle(fontSize: 26)),
|
|
||||||
const SizedBox(width: 6),
|
|
||||||
const Icon(Icons.chevron_right, color: Color(0xFF888888)),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue