getWatchLocationStream method
The function returns a stream of location updates by listening to a broadcast stream and converting the received data into Location objects. @returns The method is returning a Stream of Location objects.
Implementation
@override
Stream<Location>? getWatchLocationStream() {
if (_locationStream == null) {
_locationStream = _locationStreamController.stream;
_locationEventChannel
.receiveBroadcastStream("location")
.map<String>((dynamic event) {
return event as String;
}).listen((locationString) {
Map<String, dynamic> data = jsonDecode(locationString);
Location location = Location.jsonToObj(data);
_locationStreamController.add(location);
});
}
return _locationStream;
}