diff options
author | Iván Ávalos <avalos@disroot.org> | 2023-05-18 20:28:09 -0600 |
---|---|---|
committer | Iván Ávalos <avalos@disroot.org> | 2023-05-18 20:28:09 -0600 |
commit | 17bd9bc740e3be5509b81d42184819324881fe54 (patch) | |
tree | 0067591909ea56bea3a2bb39324be3666e0e9ac1 /lib | |
parent | ff2da4ec4419abb0f2c68871af76f99632f649d7 (diff) | |
download | pmsna1-17bd9bc740e3be5509b81d42184819324881fe54.tar.gz pmsna1-17bd9bc740e3be5509b81d42184819324881fe54.tar.bz2 pmsna1-17bd9bc740e3be5509b81d42184819324881fe54.zip |
Added final additions
Diffstat (limited to 'lib')
-rw-r--r-- | lib/firebase/favorites.dart | 26 | ||||
-rw-r--r-- | lib/routes.dart | 4 | ||||
-rw-r--r-- | lib/screens/favorites_screen.dart | 83 | ||||
-rw-r--r-- | lib/screens/map_screen.dart | 85 |
4 files changed, 198 insertions, 0 deletions
diff --git a/lib/firebase/favorites.dart b/lib/firebase/favorites.dart new file mode 100644 index 0000000..18573b6 --- /dev/null +++ b/lib/firebase/favorites.dart @@ -0,0 +1,26 @@ +import 'package:cloud_firestore/cloud_firestore.dart'; + +class FavoritesFirebase { + final FirebaseFirestore _firestore = FirebaseFirestore.instance; + late CollectionReference _collection; + + FavoritesFirebase() { + _collection = _firestore.collection('popular_favorites'); + } + + Future<void> insertFavorite(Map<String, dynamic> map) async { + await _collection.doc().set(map); + } + + Future<void> updateFavorite(Map<String, dynamic> map, String id) async { + await _collection.doc(id).update(map); + } + + Future<void> deleteFavorite(String id) async { + await _collection.doc(id).delete(); + } + + Stream<QuerySnapshot> getAllFavorites() { + return _collection.snapshots(); + } +} diff --git a/lib/routes.dart b/lib/routes.dart index 4259727..7b64e9c 100644 --- a/lib/routes.dart +++ b/lib/routes.dart @@ -3,6 +3,8 @@ import 'package:pmsna1/screens/album_detail_screen.dart'; import 'package:pmsna1/screens/albums_screen.dart'; import 'package:pmsna1/screens/dashboard_screen.dart'; import 'package:pmsna1/screens/events_screen.dart'; +import 'package:pmsna1/screens/favorites_screen.dart'; +import 'package:pmsna1/screens/map_screen.dart'; import 'package:pmsna1/screens/new_event_screen.dart'; import 'package:pmsna1/screens/new_post_screen.dart'; import 'package:pmsna1/screens/onboarding_screen.dart'; @@ -23,5 +25,7 @@ Map<String, WidgetBuilder> getApplicationRoutes() { '/newevent': (BuildContext context) => const NewEventScreen(), '/albums': (BuildContext context) => const AlbumsScreen(), '/album': (BuildContext context) => const AlbumDetailScreen(), + '/favorites': (BuildContext context) => const FavoritesScreen(), + '/map': (BuildContext context) => const MapSample(), }; } 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()); + }, + ), + ); + } +} diff --git a/lib/screens/map_screen.dart b/lib/screens/map_screen.dart new file mode 100644 index 0000000..db224e4 --- /dev/null +++ b/lib/screens/map_screen.dart @@ -0,0 +1,85 @@ +import 'dart:async'; + +import 'package:circular_menu/circular_menu.dart'; +import 'package:flutter/material.dart'; +import 'package:google_maps_flutter/google_maps_flutter.dart'; + +class MapSample extends StatefulWidget { + const MapSample({super.key}); + + @override + State<MapSample> createState() => MapSampleState(); +} + +class MapSampleState extends State<MapSample> { + // MapType tipoMapa = MapType.normal; + ValueNotifier<MapType> tipoMapa = ValueNotifier(MapType.normal); + + final Completer<GoogleMapController> _controller = + Completer<GoogleMapController>(); + + static const CameraPosition _kGooglePlex = CameraPosition( + target: LatLng(37.42796133580664, -122.085749655962), + zoom: 14.4746, + ); + + static const CameraPosition _kLake = CameraPosition( + bearing: 192.8334901395799, + target: LatLng(37.43296265331129, -122.08832357078792), + tilt: 59.440717697143555, + zoom: 19.151926040649414); + + CircularMenu circularMenu() => CircularMenu(items: [ + CircularMenuItem( + icon: Icons.map, + onTap: () { + tipoMapa.value = MapType.normal; + }, + ), + CircularMenuItem( + icon: Icons.satellite, + onTap: () { + tipoMapa.value = MapType.satellite; + }, + ), + CircularMenuItem( + icon: Icons.terrain, + onTap: () { + tipoMapa.value = MapType.terrain; + }, + ), + CircularMenuItem( + icon: Icons.star, + onTap: () { + tipoMapa.value = MapType.hybrid; + }, + ), + ]); + + @override + Widget build(BuildContext context) { + return Scaffold( + body: ValueListenableBuilder( + valueListenable: tipoMapa, + builder: (context, value, child) => GoogleMap( + mapType: value, + initialCameraPosition: _kGooglePlex, + onMapCreated: (GoogleMapController controller) { + _controller.complete(controller); + }, + ), + ), + // floatingActionButton: FloatingActionButton.extended( + // onPressed: _goToTheLake, + // label: const Text('To the lake!'), + // icon: const Icon(Icons.directions_boat), + // ), + floatingActionButton: circularMenu(), + ); + } + + Future<void> _goToTheLake() async { + final GoogleMapController controller = await _controller.future; + controller.animateCamera(CameraUpdate.newCameraPosition(_kLake)); + } +} |