Wrap AndroidView into a statefull widget so that it get's disposed when removed from the widget tree
What could be improved?
The AndroidView
should be wrapped into a state full widget so when a developer that uses the plugin removes this widget from the subtree, the widget get's disposed
The platform view's lifetime is the same as the lifetime of the State object for this widget. When the State is disposed the platform view (and auxiliary resources) are lazily released (some resources are immediately released and some by platform garbage collector). A stateful widget's state is disposed when the widget is removed from the tree or when it is moved within the tree. If the stateful widget has a key and it's only moved relative to its siblings, or it has a GlobalKey and it's moved within the tree, it will not be disposed.
Reverting
We are reverting this implementation, it currently causes more problems than success and the AndroidView
already does the disposing for us. So until we have a proper use-case for it. It will be reverted