Reputation: 53
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']),
Upvotes: 0
Views: 113
Reputation: 3832
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),
Upvotes: 1