FlutterFlow / flutterflow-issues

A community issue tracker for FlutterFlow.
117 stars 19 forks source link

geoflutterfire2 Querry is not working #3442

Closed vairagadeharshwardhan closed 2 months ago

vairagadeharshwardhan commented 2 months ago

Can we access your project?

Current Behavior

I want to run geoflutterfire2 Querry to get documents which are within Radius. Firebase GeoFlutterFire2 query is not working

Expected Behavior

I want documents retrieved from the querry and I can show them in list view. image

Steps to Reproduce

No Steps actually. I need to review the code for possible mistakes I might have done.

Reproducible from Blank

Bug Report Code (Required)

ITESjMmB+cpgrsQF0LncacZqhR4jNlx7bZNEidV9SQ0cCLLqE4wpWs/BMxFaXfGLen1+emCamTge+ujuvfDMG8YpPgyHba55yJFiezqXeF6WMMWKEZaSZ0FTN/FRCG6B3J+zviNSD7FuZV1pig/GSw==

Visual documentation

Firebase GeoFlutterFire2 query is not working android studio emulator screenshot.

// Automatic FlutterFlow imports import '/backend/backend.dart'; import '/backend/schema/structs/index.dart'; import '/backend/schema/enums/enums.dart'; import '/flutter_flow/flutter_flow_theme.dart'; import '/flutter_flow/flutter_flow_util.dart'; import '/custom_code/actions/index.dart'; // Imports other custom actions import '/flutter_flow/custom_functions.dart'; // Imports custom functions import 'package:flutter/material.dart'; // Begin custom action code // DO NOT REMOVE OR MODIFY THE CODE ABOVE!

import 'package:geoflutterfire2/geoflutterfire2.dart'; import 'package:cloud_firestore/cloud_firestore.dart';

final geo = GeoFlutterFire(); final _firestore = FirebaseFirestore.instance; Future<List> getNearbyTripsTest( LatLng? userLiveLocation, double? radiusInKm, ) async { // Add your function code here! try { if (userLiveLocation == null || radiusInKm == null) { throw ArgumentError('userLiveLocation and radiusInKm must not be null'); }

var client_new_lozy_bookingCollection =
    _firestore.collection('client_new_lozy_booking');
GeoFirePoint searchCenter = geo.point(
    latitude: userLiveLocation.latitude,
    longitude: userLiveLocation.longitude);
String start_point_GH_GP = 'start_point_GH_GP';

// Retrieve stores within the specified radius
var geoQuerySnapshots = await geo
    .collection(collectionRef: client_new_lozy_bookingCollection)
    .within(
        center: searchCenter,
        radius: radiusInKm,
        field: start_point_GH_GP,
        strictMode: true)
    .first;

// Extract the document IDs from the geo query results
List<String> docIds = geoQuerySnapshots.map((doc) => doc.id).toList();

// If docIds is empty, return an empty list
if (docIds.isEmpty) {
  return [];
}

// Perform a Firestore query using the document IDs
var query = _firestore
    .collection('client_new_lozy_booking')
    .where(FieldPath.documentId, whereIn: docIds);

// Get the snapshots from the query
var snapshots = await query.get();

// Convert snapshots to StoresRecord objects
return snapshots.docs
    .map((snapshot) => ClientNewLozyBookingRecord.fromSnapshot(snapshot))
    .toList();

} catch (e) { print(e); return []; } }

Environment

- FlutterFlow version: 4.1.74
- Platform:Flutterflow
- Browser name and version: Chrome latest
- Operating system and version affected: Windows 10 Pro for workstation

Additional Information

No response

msusviela commented 2 months ago

Hey @vairagadeharshwardhan, Thanks for your report, So sorry you are experiencing this issue. This is a project-specific issue and our support team is our best chance to get it solved. Do you mind following up with them? You can do that either by email: support@flutterflow.io or using the in-app chat inside of FlutterFlow. I'm going to close this issue since this tracker is specifically for bugs reproducible from blank projects. If you were able to reproduce this on a blank project as well, please let us know and provide the bug code of that project. Thanks so much!