Skip to content

Commit

Permalink
chore: add geoflutterfire_plus fetchWithin sample
Browse files Browse the repository at this point in the history
  • Loading branch information
kosukesaigusa committed Aug 17, 2023
1 parent c8c4e82 commit 665b396
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -224,6 +225,17 @@ class DevelopmentItemsPage extends ConsumerWidget {
),
onTap: () => context.router.pushNamed(ColorPage.location),
),
ListTile(
title: const Text(
'geoflutterfire_plus の機能確認',
),
onTap: () => Navigator.push<void>(
context,
MaterialPageRoute(
builder: (context) => const GeoflutterfirePlusSample(),
),
),
),
],
),
);
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, dynamic>)['geopoint'] as GeoPoint,
);
debugPrint(result.toString());
},
),
],
),
);
}
}

0 comments on commit 665b396

Please sign in to comment.