mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 22:09:06 +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:
@@ -58,6 +58,7 @@ class _HomePageState extends State<HomePage> {
|
|||||||
batteryLevel = result;
|
batteryLevel = result;
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
if (!context.mounted) return;
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
backgroundColor: Theme.of(context).primaryColor,
|
backgroundColor: Theme.of(context).primaryColor,
|
||||||
|
|||||||
@@ -134,14 +134,16 @@ class _PlaceMapState extends State<PlaceMap> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> onMapCreated(GoogleMapController controller) async {
|
Future<void> onMapCreated(GoogleMapController controller) async {
|
||||||
|
if (!context.mounted) return;
|
||||||
|
final appState = Provider.of<AppState>(context, listen: false);
|
||||||
mapController.complete(controller);
|
mapController.complete(controller);
|
||||||
_lastMapPosition = widget.center;
|
_lastMapPosition = widget.center;
|
||||||
|
|
||||||
// Draw initial place markers on creation so that we have something
|
// Draw initial place markers on creation so that we have something
|
||||||
// interesting to look at.
|
// interesting to look at.
|
||||||
var markers = <Marker>{};
|
var markers = <Marker>{};
|
||||||
for (var place in Provider.of<AppState>(context, listen: false).places) {
|
for (var place in appState.places) {
|
||||||
markers.add(await _createPlaceMarker(context, place));
|
markers.add(await _createPlaceMarker(place, appState.selectedCategory));
|
||||||
}
|
}
|
||||||
setState(() {
|
setState(() {
|
||||||
_markers.addAll(markers);
|
_markers.addAll(markers);
|
||||||
@@ -180,6 +182,7 @@ class _PlaceMapState extends State<PlaceMap> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _confirmAddPlace(BuildContext context) async {
|
Future<void> _confirmAddPlace(BuildContext context) async {
|
||||||
|
if (!context.mounted) return;
|
||||||
if (_pendingMarker != null) {
|
if (_pendingMarker != null) {
|
||||||
// Create a new Place and map it to the marker we just added.
|
// Create a new Place and map it to the marker we just added.
|
||||||
final appState = Provider.of<AppState>(context, listen: false);
|
final appState = Provider.of<AppState>(context, listen: false);
|
||||||
@@ -192,8 +195,7 @@ class _PlaceMapState extends State<PlaceMap> {
|
|||||||
|
|
||||||
final scaffoldMessenger = ScaffoldMessenger.of(context);
|
final scaffoldMessenger = ScaffoldMessenger.of(context);
|
||||||
|
|
||||||
var placeMarker =
|
var placeMarker = await _getPlaceMarkerIcon(appState.selectedCategory);
|
||||||
await _getPlaceMarkerIcon(context, appState.selectedCategory);
|
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
final updatedMarker = _pendingMarker!.copyWith(
|
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(
|
final marker = Marker(
|
||||||
markerId: MarkerId(place.latLng.toString()),
|
markerId: MarkerId(place.latLng.toString()),
|
||||||
position: place.latLng,
|
position: place.latLng,
|
||||||
@@ -246,9 +251,8 @@ class _PlaceMapState extends State<PlaceMap> {
|
|||||||
snippet: '${place.starRating} Star Rating',
|
snippet: '${place.starRating} Star Rating',
|
||||||
onTap: () => context.go('/place/${place.id}'),
|
onTap: () => context.go('/place/${place.id}'),
|
||||||
),
|
),
|
||||||
icon: await _getPlaceMarkerIcon(context, place.category),
|
icon: await _getPlaceMarkerIcon(place.category),
|
||||||
visible: place.category ==
|
visible: place.category == selectedCategory,
|
||||||
Provider.of<AppState>(context, listen: false).selectedCategory,
|
|
||||||
);
|
);
|
||||||
_markedPlaces[marker] = place;
|
_markedPlaces[marker] = place;
|
||||||
return marker;
|
return marker;
|
||||||
@@ -400,8 +404,7 @@ class _PlaceMapState extends State<PlaceMap> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<BitmapDescriptor> _getPlaceMarkerIcon(
|
Future<BitmapDescriptor> _getPlaceMarkerIcon(PlaceCategory category) =>
|
||||||
BuildContext context, PlaceCategory category) =>
|
|
||||||
switch (category) {
|
switch (category) {
|
||||||
PlaceCategory.favorite => BitmapDescriptor.fromAssetImage(
|
PlaceCategory.favorite => BitmapDescriptor.fromAssetImage(
|
||||||
createLocalImageConfiguration(context, size: const Size.square(32)),
|
createLocalImageConfiguration(context, size: const Size.square(32)),
|
||||||
|
|||||||
@@ -53,7 +53,8 @@ declare -ar PROJECT_NAMES=(
|
|||||||
"material_3_demo"
|
"material_3_demo"
|
||||||
# TODO(DomesticMouse): The '!' will have no effect because the receiver can't be null.
|
# TODO(DomesticMouse): The '!' will have no effect because the receiver can't be null.
|
||||||
# "navigation_and_routing"
|
# "navigation_and_routing"
|
||||||
"next_gen_ui_demo"
|
# TODO: Dependency 'gap-3.0.0' fails to compile
|
||||||
|
# "next_gen_ui_demo"
|
||||||
"place_tracker"
|
"place_tracker"
|
||||||
# TODO: https://github.com/flutter/samples/issues/1765
|
# TODO: https://github.com/flutter/samples/issues/1765
|
||||||
# "platform_channels"
|
# "platform_channels"
|
||||||
|
|||||||
Reference in New Issue
Block a user