mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 13:58:47 +00:00
Fix master channel build (#1900)
- Fixes #1899 - Don't use BuildContext in async. - Disabled build script for `next-gen-ui-demo` for master channel because dependency gap does not compile. - Improve use BuildContext in `place_tracker`, added checks to verify that the context is still mounted, and avoid passing BuildContext as parameter. ## Pre-launch Checklist - [ ] I read the [Flutter Style Guide] _recently_, and have followed its advice. - [ ] I signed the [CLA]. - [ ] I read the [Contributors Guide]. - [ ] I updated/added relevant documentation (doc comments with `///`). - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-devrel channel on [Discord]. <!-- Links --> [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [CLA]: https://cla.developers.google.com/ [Discord]: https://github.com/flutter/flutter/wiki/Chat [Contributors Guide]: https://github.com/flutter/samples/blob/main/CONTRIBUTING.md
This commit is contained in:
@@ -134,14 +134,16 @@ class _PlaceMapState extends State<PlaceMap> {
|
||||
}
|
||||
|
||||
Future<void> onMapCreated(GoogleMapController controller) async {
|
||||
if (!context.mounted) return;
|
||||
final appState = Provider.of<AppState>(context, listen: false);
|
||||
mapController.complete(controller);
|
||||
_lastMapPosition = widget.center;
|
||||
|
||||
// Draw initial place markers on creation so that we have something
|
||||
// interesting to look at.
|
||||
var markers = <Marker>{};
|
||||
for (var place in Provider.of<AppState>(context, listen: false).places) {
|
||||
markers.add(await _createPlaceMarker(context, place));
|
||||
for (var place in appState.places) {
|
||||
markers.add(await _createPlaceMarker(place, appState.selectedCategory));
|
||||
}
|
||||
setState(() {
|
||||
_markers.addAll(markers);
|
||||
@@ -180,6 +182,7 @@ class _PlaceMapState extends State<PlaceMap> {
|
||||
}
|
||||
|
||||
Future<void> _confirmAddPlace(BuildContext context) async {
|
||||
if (!context.mounted) return;
|
||||
if (_pendingMarker != null) {
|
||||
// Create a new Place and map it to the marker we just added.
|
||||
final appState = Provider.of<AppState>(context, listen: false);
|
||||
@@ -192,8 +195,7 @@ class _PlaceMapState extends State<PlaceMap> {
|
||||
|
||||
final scaffoldMessenger = ScaffoldMessenger.of(context);
|
||||
|
||||
var placeMarker =
|
||||
await _getPlaceMarkerIcon(context, appState.selectedCategory);
|
||||
var placeMarker = await _getPlaceMarkerIcon(appState.selectedCategory);
|
||||
|
||||
setState(() {
|
||||
final updatedMarker = _pendingMarker!.copyWith(
|
||||
@@ -237,7 +239,10 @@ class _PlaceMapState extends State<PlaceMap> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<Marker> _createPlaceMarker(BuildContext context, Place place) async {
|
||||
Future<Marker> _createPlaceMarker(
|
||||
Place place,
|
||||
PlaceCategory selectedCategory,
|
||||
) async {
|
||||
final marker = Marker(
|
||||
markerId: MarkerId(place.latLng.toString()),
|
||||
position: place.latLng,
|
||||
@@ -246,9 +251,8 @@ class _PlaceMapState extends State<PlaceMap> {
|
||||
snippet: '${place.starRating} Star Rating',
|
||||
onTap: () => context.go('/place/${place.id}'),
|
||||
),
|
||||
icon: await _getPlaceMarkerIcon(context, place.category),
|
||||
visible: place.category ==
|
||||
Provider.of<AppState>(context, listen: false).selectedCategory,
|
||||
icon: await _getPlaceMarkerIcon(place.category),
|
||||
visible: place.category == selectedCategory,
|
||||
);
|
||||
_markedPlaces[marker] = place;
|
||||
return marker;
|
||||
@@ -400,8 +404,7 @@ class _PlaceMapState extends State<PlaceMap> {
|
||||
});
|
||||
}
|
||||
|
||||
static Future<BitmapDescriptor> _getPlaceMarkerIcon(
|
||||
BuildContext context, PlaceCategory category) =>
|
||||
Future<BitmapDescriptor> _getPlaceMarkerIcon(PlaceCategory category) =>
|
||||
switch (category) {
|
||||
PlaceCategory.favorite => BitmapDescriptor.fromAssetImage(
|
||||
createLocalImageConfiguration(context, size: const Size.square(32)),
|
||||
|
||||
Reference in New Issue
Block a user