Skip to content

Instantly share code, notes, and snippets.

@marinat
Last active October 30, 2019 09:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marinat/7d2e3216b2b19e26116cfd60541b72c1 to your computer and use it in GitHub Desktop.
Save marinat/7d2e3216b2b19e26116cfd60541b72c1 to your computer and use it in GitHub Desktop.
class MapBloc extends Bloc<MapEvent, MapState> { ...
Set<Marker> _markers = Set();
Set<Marker> getMarkers() {
return _markers;
}
...
@override
Stream<MapState> mapEventToState(
MapEvent event,
) async* {
if (event is UpdateMarkersData) {
_clusteringHelper.updateData(event.data);
yield Redrawing();
}
if (event is MarkersUpdated) {
yield Updated();
}
...
abstract class MapState extends Equatable {
@override
List<Object> get props => [];
}
class Updated extends MapState {
}
class Redrawing extends MapState {
}
....
Widget _map(BuildContext context) {
return BlocBuilder<MapBloc, MapState>(builder: (context, state) {
return GoogleMap(
key: _keyMap,
onMapCreated: (GoogleMapController controller) {
_mapController = controller;
BlocProvider.of<MapBloc>(context)
.add(MapLoaded(mapController: controller));
},
myLocationEnabled: true,
myLocationButtonEnabled: false,
markers: BlocProvider.of<MapBloc>(context).getMarkers(),
initialCameraPosition: CameraPosition(target: _center, zoom: 3.0),
onCameraIdle: () => BlocProvider.of<MapBloc>(context).add(CameraIdle()),
onCameraMove: (newPosition) => BlocProvider.of<MapBloc>(context)
.add(CameraMove(position: newPosition)),
);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment