Last active
October 30, 2019 09:12
-
-
Save marinat/7d2e3216b2b19e26116cfd60541b72c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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