MapBloc constructor
MapBloc({
- required LocationBloc locationBloc,
Implementation
MapBloc({required this.locationBloc}) : super(const MapState()) {
on<OnMapInitializedEvent>(_onInitMap);
on<OnStartFollowingUserEvent>(
(event, emit) => emit(state.copyWith(isFollowingUser: true)));
on<OnStopFollowingUserEvent>(
(event, emit) => emit(state.copyWith(isFollowingUser: false)));
on<UpdateUserPolylineEvent>(_onUpdatePolyline);
on<OnToggleUserRoute>(
(event, emit) => emit(state.copyWith(showMyRoute: !state.showMyRoute)));
on<DisplayPolylinesEvent>((event, emit) => emit(
state.copyWith(polylines: event.polylines, markers: event.markers)));
locationStateSubscription = locationBloc.stream.listen((locationState) {
if (locationState.lastKnownLocation != null) {
add(UpdateUserPolylineEvent(locationState.myLocationHistory));
}
if (!state.isFollowingUser) return;
if (locationState.lastKnownLocation == null) return;
moveCamera(locationState.lastKnownLocation!);
});
}