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
pull/1902/head
Miguel Beltran 2 years ago committed by GitHub
parent 2c646f04be
commit bce29a0ff2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -58,6 +58,7 @@ class _HomePageState extends State<HomePage> {
batteryLevel = result;
});
} catch (error) {
if (!context.mounted) return;
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
backgroundColor: Theme.of(context).primaryColor,

@ -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)),

@ -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"

Loading…
Cancel
Save