0

I am trying to return location values ​​with StreamBuilder, but I have not been successful. In debug, he doesn't even run the builder. I can't find the problem.

Here I create StreamBuilder, to bring the location

_newMoveToApoio(String uidProp) { StreamBuilder( stream: Firestore.instance .collection('tracker') .document(uidProp) .snapshots(), builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.waiting) { return new Center( child: CircularProgressIndicator(), ); } else { var trackerDocument = snapshot.data; double latitude = trackerDocument['latitude']; double longitude = trackerDocument['longitude']; _controller.animateCamera(CameraUpdate.newCameraPosition( CameraPosition( target: LatLng(latitude, longitude), zoom: 18.0))); setState(() { _markers.add( Marker( draggable: false, markerId: MarkerId("1"), position: LatLng(latitude, longitude), infoWindow: InfoWindow( title: "João Marcelo", snippet: "Sua Localização Atual"), icon: _markerIconApoio, ), ); }); } }); } 

Here I make the call in a bottomsheet, passing the 'uid'

onTap: () => _newMoveToApoio(snapshot.data[index].data['uidProp']), 

1 Answer 1

1

I think you misunderstand what StreamBuilder is for. It is a widget to be used in a widget tree. But you call it from an onTap which just executes the function. You may want something more like this :

_newMoveToApoio(String uidProp) async { var snapshot = await Firestore.instance .collection('tracker') .document(uidProp) .get(); // do your business logic here } 

EDIT : To use the StreamBuilder inside the tree, first return it :

Widget _newMoveToApoio(String uidProp) { return StreamBuilder( // the rest of the function 

and then inside your build method :

RandomWidget( child: _newMoveToApoio(uidProp), 
Sign up to request clarification or add additional context in comments.

4 Comments

Your answer is right! It's just that I'm starting to learn flutter now, and I still have doubts. Now, how could I get real-time responses from the firestore? I had used StreamBuilder for this purpose.
I think your code is correct. You get updates with snapshots(). just add return before StreamBuilder and add _newMoveToApoio(uidProp) where you want it in your widget tree.
Sorry, I couldn't understand. Can you give me an example, please?
I tried to use StreamBuilder as you indicated, but it didn't work ... The first way using get (), is working.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.