From bce29a0ff29268a1912126b045c4b0e7e334ff9e Mon Sep 17 00:00:00 2001 From: Miguel Beltran Date: Tue, 20 Jun 2023 13:29:56 +0200 Subject: [PATCH] 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]. [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 --- .../federated_plugin/example/lib/main.dart | 1 + place_tracker/lib/place_map.dart | 23 +++++++++++-------- tool/flutter_ci_script_master.sh | 3 ++- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/experimental/federated_plugin/federated_plugin/example/lib/main.dart b/experimental/federated_plugin/federated_plugin/example/lib/main.dart index cbce95ba7..c9f64ff09 100644 --- a/experimental/federated_plugin/federated_plugin/example/lib/main.dart +++ b/experimental/federated_plugin/federated_plugin/example/lib/main.dart @@ -58,6 +58,7 @@ class _HomePageState extends State { batteryLevel = result; }); } catch (error) { + if (!context.mounted) return; ScaffoldMessenger.of(context).showSnackBar( SnackBar( backgroundColor: Theme.of(context).primaryColor, diff --git a/place_tracker/lib/place_map.dart b/place_tracker/lib/place_map.dart index d4fe7d5af..4219d0232 100644 --- a/place_tracker/lib/place_map.dart +++ b/place_tracker/lib/place_map.dart @@ -134,14 +134,16 @@ class _PlaceMapState extends State { } Future onMapCreated(GoogleMapController controller) async { + if (!context.mounted) return; + final appState = Provider.of(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 = {}; - for (var place in Provider.of(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 { } Future _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(context, listen: false); @@ -192,8 +195,7 @@ class _PlaceMapState extends State { 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 { } } - Future _createPlaceMarker(BuildContext context, Place place) async { + Future _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 { snippet: '${place.starRating} Star Rating', onTap: () => context.go('/place/${place.id}'), ), - icon: await _getPlaceMarkerIcon(context, place.category), - visible: place.category == - Provider.of(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 { }); } - static Future _getPlaceMarkerIcon( - BuildContext context, PlaceCategory category) => + Future _getPlaceMarkerIcon(PlaceCategory category) => switch (category) { PlaceCategory.favorite => BitmapDescriptor.fromAssetImage( createLocalImageConfiguration(context, size: const Size.square(32)), diff --git a/tool/flutter_ci_script_master.sh b/tool/flutter_ci_script_master.sh index c9c6c43bf..afd6d5e95 100755 --- a/tool/flutter_ci_script_master.sh +++ b/tool/flutter_ci_script_master.sh @@ -53,7 +53,8 @@ declare -ar PROJECT_NAMES=( "material_3_demo" # TODO(DomesticMouse): The '!' will have no effect because the receiver can't be null. # "navigation_and_routing" - "next_gen_ui_demo" + # TODO: Dependency 'gap-3.0.0' fails to compile + # "next_gen_ui_demo" "place_tracker" # TODO: https://github.com/flutter/samples/issues/1765 # "platform_channels"