From 665b396402b77ac7586e462d97f1780057707e14 Mon Sep 17 00:00:00 2001 From: Kosuke Saigusa Date: Thu, 17 Aug 2023 09:30:47 +0900 Subject: [PATCH] chore: add geoflutterfire_plus fetchWithin sample --- .../ui/development_items.dart | 12 ++++++ .../geoflutterfire_plus.dart | 38 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 packages/mottai_flutter_app/lib/development/geoflutterfire_plus/geoflutterfire_plus.dart diff --git a/packages/mottai_flutter_app/lib/development/development_items/ui/development_items.dart b/packages/mottai_flutter_app/lib/development/development_items/ui/development_items.dart index d73cd0ec..9f0a074b 100644 --- a/packages/mottai_flutter_app/lib/development/development_items/ui/development_items.dart +++ b/packages/mottai_flutter_app/lib/development/development_items/ui/development_items.dart @@ -17,6 +17,7 @@ import '../../color/ui/color.dart'; import '../../firebase_storage/ui/firebase_storage.dart'; import '../../force_update/ui/force_update.dart'; import '../../generic_image/ui/generic_images.dart'; +import '../../geoflutterfire_plus/geoflutterfire_plus.dart'; import '../../image_detail_view/ui/image_detail_view_stub.dart'; import '../../image_picker/ui/image_picker_sample.dart'; import '../../in_review/ui/in_review.dart'; @@ -224,6 +225,17 @@ class DevelopmentItemsPage extends ConsumerWidget { ), onTap: () => context.router.pushNamed(ColorPage.location), ), + ListTile( + title: const Text( + 'geoflutterfire_plus の機能確認', + ), + onTap: () => Navigator.push( + context, + MaterialPageRoute( + builder: (context) => const GeoflutterfirePlusSample(), + ), + ), + ), ], ), ); diff --git a/packages/mottai_flutter_app/lib/development/geoflutterfire_plus/geoflutterfire_plus.dart b/packages/mottai_flutter_app/lib/development/geoflutterfire_plus/geoflutterfire_plus.dart new file mode 100644 index 00000000..428453a2 --- /dev/null +++ b/packages/mottai_flutter_app/lib/development/geoflutterfire_plus/geoflutterfire_plus.dart @@ -0,0 +1,38 @@ +import 'package:cloud_firestore/cloud_firestore.dart'; +import 'package:flutter/material.dart'; +import 'package:geoflutterfire_plus/geoflutterfire_plus.dart'; + +/// geoflutterfire_plus パッケージの動作確認用 Widget. +class GeoflutterfirePlusSample extends StatelessWidget { + const GeoflutterfirePlusSample({super.key}); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar(), + body: ListView( + children: [ + ListTile( + leading: const Icon(Icons.map), + title: const Text('Call fetchWithin method'), + onTap: () async { + final locationCollectionRef = + FirebaseFirestore.instance.collection('locations'); + const center = GeoFirePoint(GeoPoint(35.681236, 139.767125)); + final result = await GeoCollectionReference(locationCollectionRef) + .fetchWithin( + center: center, + radiusInKm: 6, + field: 'geo', + strictMode: true, + geopointFrom: (data) => (data['geo'] + as Map)['geopoint'] as GeoPoint, + ); + debugPrint(result.toString()); + }, + ), + ], + ), + ); + } +}