I was using google_maps_flutter library in my project. While i hot reload the map or back to map from another view then it crashes with message :
Exception has occurred.
PlatformException (PlatformException(error, java.lang.IllegalStateException: Trying to create an already created platform view, view id: 0
at io.flutter.plugin.platform.PlatformViewsController$1.createPlatformView(PlatformViewsController.java:85)
at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:96)
So i was trying to dispose the map and its controller. i got a code snippet to dispose in this article So i added this code snippet:
@override
void dispose() {
_disposeController();
super.dispose();
}
Future<void> _disposeController() async{
final GoogleMapController controller = await _controller.future;
//controller.dispose();
}
but uncommenting last line was giving this error:
The method 'dispose' isn't defined for the class 'GoogleMapController'.
Try correcting the name to the name of an existing method, or defining a method named 'dispose'.
then how can i dispose the controller?