History pagedart » History » Version 1
cristobal hernandez, 12/18/2025 01:42 AM
| 1 | 1 | cristobal hernandez | --- |
|---|---|---|---|
| 2 | 1 | cristobal hernandez | |
| 3 | 1 | cristobal hernandez | | [[Interfaz|⌂]] | [[home_page.dart]] | [[feeding_page.dart]] | [[connection_page.dart]] | [[config_page.dart]] | |
| 4 | 1 | cristobal hernandez | |
| 5 | 1 | cristobal hernandez | --- |
| 6 | 1 | cristobal hernandez | |
| 7 | 1 | cristobal hernandez | h1. history_page.dart |
| 8 | 1 | cristobal hernandez | |
| 9 | 1 | cristobal hernandez | <pre><code class="java"> |
| 10 | 1 | cristobal hernandez | |
| 11 | 1 | cristobal hernandez | import 'package:flutter/material.dart'; |
| 12 | 1 | cristobal hernandez | import 'package:cloud_firestore/cloud_firestore.dart'; |
| 13 | 1 | cristobal hernandez | |
| 14 | 1 | cristobal hernandez | class HistoryPage extends StatelessWidget { |
| 15 | 1 | cristobal hernandez | final String aquariumId; |
| 16 | 1 | cristobal hernandez | |
| 17 | 1 | cristobal hernandez | const HistoryPage({super.key, required this.aquariumId}); |
| 18 | 1 | cristobal hernandez | |
| 19 | 1 | cristobal hernandez | @override |
| 20 | 1 | cristobal hernandez | Widget build(BuildContext context) { |
| 21 | 1 | cristobal hernandez | return Scaffold( |
| 22 | 1 | cristobal hernandez | backgroundColor: const Color(0xFF001B2E), |
| 23 | 1 | cristobal hernandez | appBar: AppBar( |
| 24 | 1 | cristobal hernandez | title: const Text("Historial de Alertas", style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold)), |
| 25 | 1 | cristobal hernandez | backgroundColor: Colors.transparent, |
| 26 | 1 | cristobal hernandez | iconTheme: const IconThemeData(color: Colors.white), |
| 27 | 1 | cristobal hernandez | elevation: 0, |
| 28 | 1 | cristobal hernandez | ), |
| 29 | 1 | cristobal hernandez | body: StreamBuilder<QuerySnapshot>( |
| 30 | 1 | cristobal hernandez | stream: FirebaseFirestore.instance |
| 31 | 1 | cristobal hernandez | .collection('acuarios') |
| 32 | 1 | cristobal hernandez | .doc(aquariumId) |
| 33 | 1 | cristobal hernandez | .collection('historial') |
| 34 | 1 | cristobal hernandez | .orderBy('timestamp', descending: true) |
| 35 | 1 | cristobal hernandez | .limit(50) |
| 36 | 1 | cristobal hernandez | .snapshots(), |
| 37 | 1 | cristobal hernandez | builder: (context, snapshot) { |
| 38 | 1 | cristobal hernandez | if (snapshot.hasError) return const Center(child: Text("Error cargando historial", style: TextStyle(color: Colors.white))); |
| 39 | 1 | cristobal hernandez | if (snapshot.connectionState == ConnectionState.waiting) return const Center(child: CircularProgressIndicator(color: Color(0xFFFF5400))); |
| 40 | 1 | cristobal hernandez | |
| 41 | 1 | cristobal hernandez | final docs = snapshot.data!.docs; |
| 42 | 1 | cristobal hernandez | |
| 43 | 1 | cristobal hernandez | if (docs.isEmpty) { |
| 44 | 1 | cristobal hernandez | return Center( |
| 45 | 1 | cristobal hernandez | child: Column( |
| 46 | 1 | cristobal hernandez | mainAxisAlignment: MainAxisAlignment.center, |
| 47 | 1 | cristobal hernandez | children: [ |
| 48 | 1 | cristobal hernandez | Icon(Icons.history_toggle_off, size: 70, color: Colors.white.withOpacity(0.2)), |
| 49 | 1 | cristobal hernandez | const SizedBox(height: 10), |
| 50 | 1 | cristobal hernandez | Text("Sin alertas registradas", style: TextStyle(color: Colors.white.withOpacity(0.5))), |
| 51 | 1 | cristobal hernandez | ], |
| 52 | 1 | cristobal hernandez | ), |
| 53 | 1 | cristobal hernandez | ); |
| 54 | 1 | cristobal hernandez | } |
| 55 | 1 | cristobal hernandez | |
| 56 | 1 | cristobal hernandez | return ListView.builder( |
| 57 | 1 | cristobal hernandez | padding: const EdgeInsets.all(15), |
| 58 | 1 | cristobal hernandez | itemCount: docs.length, |
| 59 | 1 | cristobal hernandez | itemBuilder: (context, index) { |
| 60 | 1 | cristobal hernandez | final data = docs[index].data() as Map<String, dynamic>; |
| 61 | 1 | cristobal hernandez | |
| 62 | 1 | cristobal hernandez | // Diseño de cada fila del historial |
| 63 | 1 | cristobal hernandez | return Container( |
| 64 | 1 | cristobal hernandez | margin: const EdgeInsets.only(bottom: 10), |
| 65 | 1 | cristobal hernandez | decoration: BoxDecoration( |
| 66 | 1 | cristobal hernandez | color: Colors.white.withOpacity(0.05), |
| 67 | 1 | cristobal hernandez | borderRadius: BorderRadius.circular(15), |
| 68 | 1 | cristobal hernandez | border: Border(left: BorderSide(color: Colors.redAccent.shade400, width: 4)), |
| 69 | 1 | cristobal hernandez | ), |
| 70 | 1 | cristobal hernandez | child: ListTile( |
| 71 | 1 | cristobal hernandez | contentPadding: const EdgeInsets.symmetric(horizontal: 15, vertical: 5), |
| 72 | 1 | cristobal hernandez | leading: const CircleAvatar( |
| 73 | 1 | cristobal hernandez | backgroundColor: Color(0xFF3E1313), |
| 74 | 1 | cristobal hernandez | child: Icon(Icons.warning_amber_rounded, color: Colors.redAccent), |
| 75 | 1 | cristobal hernandez | ), |
| 76 | 1 | cristobal hernandez | title: Text( |
| 77 | 1 | cristobal hernandez | data['mensaje'] ?? "Alerta", |
| 78 | 1 | cristobal hernandez | style: const TextStyle(color: Colors.white, fontWeight: FontWeight.bold), |
| 79 | 1 | cristobal hernandez | ), |
| 80 | 1 | cristobal hernandez | subtitle: Text( |
| 81 | 1 | cristobal hernandez | data['fecha'] ?? "--/--/--", |
| 82 | 1 | cristobal hernandez | style: TextStyle(color: Colors.white.withOpacity(0.5)), |
| 83 | 1 | cristobal hernandez | ), |
| 84 | 1 | cristobal hernandez | ), |
| 85 | 1 | cristobal hernandez | ); |
| 86 | 1 | cristobal hernandez | }, |
| 87 | 1 | cristobal hernandez | ); |
| 88 | 1 | cristobal hernandez | }, |
| 89 | 1 | cristobal hernandez | ), |
| 90 | 1 | cristobal hernandez | ); |
| 91 | 1 | cristobal hernandez | } |
| 92 | 1 | cristobal hernandez | } |
| 93 | 1 | cristobal hernandez | |
| 94 | 1 | cristobal hernandez | </code></pre> |