You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[google_maps_flutter] Fixes exception when dispose is called while asynchronous update from didUpdateWidget is executed (#9227)
This PR fixes an exception in Google Maps Flutter which occurs when dispose is called while asynchronous code is executed from didUpdateWidget.
flutter/flutter#43785
I've done the work in 2 commits, the first one just used mount checks on after each awaited retrieval of the controller.
The second reuses the controller to limit the number of awaited async calls.
I am a little unsure of the expected execution order of all the unawaited futures which update the controller in regards to whether dispose could still be called in between their executions.
Testing locally I haven't been able to reproduce the exception with a single awaited controller.
I bumped the version 2.12.2 as no feature behaviour has changed.
No new tests in this PR, I'm not sure that you can test this change using widget tests.
Existing test coverage ensures that the values are still being updated correctly.
## Pre-Review Checklist
- [/] I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
- [/] I read the [Tree Hygiene] page, which explains my responsibilities.
- [/] I read and followed the [relevant style guides] and ran [the auto-formatter].
- [/] I signed the [CLA].
- [/] The title of the PR starts with the name of the package surrounded by square brackets, e.g. `[shared_preferences]`
- [/] I [linked to at least one issue that this PR fixes] in the description above.
- [/] I updated `pubspec.yaml` with an appropriate new version according to the [pub versioning philosophy], or I have commented below to indicate which [version change exemption] this PR falls under[^1].
- [/] I updated `CHANGELOG.md` to add a description of the change, [following repository CHANGELOG style], or I have commented below to indicate which [CHANGELOG exemption] this PR falls under[^1].
- [/] I updated/added any relevant documentation (doc comments with `///`).
- [/] I added new tests to check the change I am making, or I have commented below to indicate which [test exemption] this PR falls under[^1].
- [/] All existing and new tests are passing.
[^1]: Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling.
## Code Sample
This sample app can be used to trigger the error, just repeatedly tapping the button at the bottom of the screen to reload the map. I did the testing in Chrome using the google_maps_flutter_web example project and the javascript key in web/index.html
```
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
void main() {
runApp(const MapToggleWidget());
}
class MapToggleWidget extends StatefulWidget {
const MapToggleWidget({Key? key}) : super(key: key);
@OverRide
_MapToggleWidgetState createState() => _MapToggleWidgetState();
}
class _MapToggleWidgetState extends State<MapToggleWidget> {
bool _showMap = true;
@OverRide
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Map Toggle Example')),
body: Column(
children: [
Expanded(child: _showMap ? buildGoogleMap() : buildNoMapContainer()),
Padding(
padding: const EdgeInsets.all(8.0),
child: ElevatedButton(
onPressed: () => setState(() => _showMap = !_showMap),
child: Text(_showMap ? 'Hide Map' : 'Show Map'),
),
),
],
),
),
);
}
Container buildNoMapContainer() {
return Container(
color: Colors.grey[300],
child: const Center(
child: Text(
'Map is hidden',
style: TextStyle(fontSize: 18),
),
),
);
}
GoogleMap buildGoogleMap() {
return const GoogleMap(
mapType: MapType.satellite,
initialCameraPosition: CameraPosition(
target: LatLng(-38.9000, 175.8000),
zoom: 10.0,
),
);
}
}
```
0 commit comments