Streambuilder does not return value - Flutter

Asked

Viewed 64 times

0

Hello!

I’m trying to return location values with StreamBuilder, but I’m not succeeding.

In debug, it doesn’t even run Builder. I can’t find the problem.

Here I create the 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 on a bottomsheet, passing the 'uid'

onTap: () =>  _newMoveToApoio(snapshot.data[index].data['uidProp']),
  • Its function _newMoveToApoio doesn’t return anything? Is that right? Only runs the Streambuilder constructor and does not use this object for anything? Also, what would you like to be done with this onTap? Just calling this function so will not do anything at all. I couldn’t understand your intention.

  • @Naslausky I was not using the Streambuilder in the correct way. On another channel of doubts, one managed to point out to me the correct way. I will put the answer here to help others with the same difficulty.

1 answer

1

I’m answering so I can help other people. This was the solution found.

_newMoveToApoio(String uidProp) async {
  var snapshot = await Firestore.instance
            .collection('tracker')
            .document(uidProp)
            .get();
  // Codigo aqui
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.