4

I am trying to use flutter_bloc with multiple streams from my location service and I need to accommodate multiple streams from the service to either emit a state or further get the data from other streams.

Future<void> _onGetLocation(GetLocation event, Emitter<HomeState> emit) async {
    emit.forEach(LocationService.serviceStatusStream, onData(serviceStatus){
         if(serviceStatus==ServiceStatus.enabled){
             // here I want to again access the permission stream
             // if permission stream gives PermissionStatus.granted 
             // then I need to get the Location stream and return the 
             // HomeLocationLoaded() with current position other 
             // Other intermediate states (permission denied, location null
             // will have a separate state emit during the process
         }
         return HomeLocationOff();
     })  
    
  }

Basically, I have three streams connected in the following order ServiceStream -> Permission Stream -> Location Stream. Looking for suggestions to implement it according to the new flutter_bloc 8.x.x recommended way.

I have initially planned to combine the 3 streams into one but that doesn't seem efficient as I will be listening to the permission stream and location stream even if the location service is off. Or I would be listening to the location stream even if the permission status is denied.

Abuzar Rasool
  • 79
  • 1
  • 9

0 Answers0