diff options
Diffstat (limited to 'lib/screens/favorites_screen.dart')
-rw-r--r-- | lib/screens/favorites_screen.dart | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/lib/screens/favorites_screen.dart b/lib/screens/favorites_screen.dart new file mode 100644 index 0000000..74432a7 --- /dev/null +++ b/lib/screens/favorites_screen.dart @@ -0,0 +1,83 @@ +import 'package:flutter/material.dart'; +import 'package:pmsna1/firebase/favorites.dart'; + +class FavoritesScreen extends StatefulWidget { + const FavoritesScreen({super.key}); + + @override + State<FavoritesScreen> createState() => _FavoritesScreenState(); +} + +class _FavoritesScreenState extends State<FavoritesScreen> { + final FavoritesFirebase _firebase = FavoritesFirebase(); + + @override + Widget build(BuildContext context) { + return Scaffold( + body: StreamBuilder( + stream: _firebase.getAllFavorites(), + builder: (context, snapshot) { + if (snapshot.hasData) { + return ListView.builder( + itemCount: snapshot.data!.size, + itemBuilder: (context, index) => ListTile( + title: Text(snapshot.data!.docs[index].get('title')), + trailing: Row( + mainAxisSize: MainAxisSize.min, + children: [ + IconButton( + onPressed: () { + // _firebase.insertFavorite({ + // 'title': snapshot.data!.docs[index].get('title') + // }) + }, + icon: Icon( + Icons.favorite, + color: Theme.of(context).colorScheme.onBackground, + ), + ), + IconButton( + onPressed: () { + showDialog( + context: context, + builder: (context) => AlertDialog( + title: const Text('Confirmar borrado'), + content: const Text('¿Desea borrar el post?'), + actions: [ + TextButton( + child: const Text('Sí'), + onPressed: () { + // Delete post + _firebase.deleteFavorite( + snapshot.data!.docs[index].id); + Navigator.of(context).pop(); + }, + ), + TextButton( + child: const Text('No'), + onPressed: () { + Navigator.of(context).pop(); + }, + ) + ], + ), + ); + }, + icon: Icon( + Icons.delete, + color: Theme.of(context).colorScheme.onBackground, + ), + ), + ], + ), + ), + ); + } else if (snapshot.hasError) { + return const Center(child: Text('Hubo un error')); + } + return const Center(child: CircularProgressIndicator()); + }, + ), + ); + } +} |