1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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());
},
),
);
}
}
|