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 | |
parent | ff2da4ec4419abb0f2c68871af76f99632f649d7 (diff) | |
download | pmsna1-17bd9bc740e3be5509b81d42184819324881fe54.tar.gz pmsna1-17bd9bc740e3be5509b81d42184819324881fe54.tar.bz2 pmsna1-17bd9bc740e3be5509b81d42184819324881fe54.zip |
Added final additions
-rw-r--r-- | android/app/src/main/AndroidManifest.xml | 3 | ||||
-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 | ||||
-rw-r--r-- | pubspec.lock | 48 | ||||
-rw-r--r-- | pubspec.yaml | 2 |
7 files changed, 251 insertions, 0 deletions
diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 94a2deb..c5ade0a 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -30,5 +30,8 @@ <meta-data android:name="flutterEmbedding" android:value="2" /> + + <meta-data android:name="com.google.android.geo.API_KEY" + android:value="AIzaSyARNyLToQtEFgaJn5GePROUcPS61xuL2QI" /> </application> </manifest> 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)); + } +} diff --git a/pubspec.lock b/pubspec.lock index 22d137d..a5e6d10 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -49,6 +49,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.2.1" + circular_menu: + dependency: "direct main" + description: + name: circular_menu + sha256: "253e5e7aaf107e84251b0c51fb66ae17f6caaebf973eb30049f02b999646373a" + url: "https://pub.dev" + source: hosted + version: "2.0.1" clock: dependency: transitive description: @@ -256,6 +264,38 @@ packages: description: flutter source: sdk version: "0.0.0" + google_maps_flutter: + dependency: "direct main" + description: + name: google_maps_flutter + sha256: "0a7e0bd1dfe594bc86892d2e69062e3f80b267e378042d82e6b87a8efc798013" + url: "https://pub.dev" + source: hosted + version: "2.2.6" + google_maps_flutter_android: + dependency: transitive + description: + name: google_maps_flutter_android + sha256: b1aeab571b33e983ced9977f2f0eca2b25925f6319e99e3901cfc1675e1b5ada + url: "https://pub.dev" + source: hosted + version: "2.4.13" + google_maps_flutter_ios: + dependency: transitive + description: + name: google_maps_flutter_ios + sha256: e9ad74415a222573625a2c1717adc1e375b18e8ce660fc12db734d1bda1132d4 + url: "https://pub.dev" + source: hosted + version: "2.2.1" + google_maps_flutter_platform_interface: + dependency: transitive + description: + name: google_maps_flutter_platform_interface + sha256: a07811d2b82055815ede75e1fe4b7b76f71a0b4820b26f71bdaddd157d6a3e20 + url: "https://pub.dev" + source: hosted + version: "2.2.6" http: dependency: "direct main" description: @@ -621,6 +661,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.1" + stream_transform: + dependency: transitive + description: + name: stream_transform + sha256: "14a00e794c7c11aa145a170587321aedce29769c08d7f58b1d141da75e3b1c6f" + url: "https://pub.dev" + source: hosted + version: "2.1.0" string_scanner: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 2285eec..e19aaa7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -26,6 +26,8 @@ dependencies: table_calendar: <=3.0.9 flutter_staggered_grid_view: ^0.6.2 cloud_firestore: ^4.5.2 + google_maps_flutter: ^2.2.6 + circular_menu: ^2.0.1 dev_dependencies: flutter_test: |