Unverified Commit 26fabcd4 authored by Stonekity's avatar Stonekity Committed by GitHub

fix memory leak of android view (#50111)

parent e92afc16
...@@ -532,6 +532,7 @@ class AndroidViewController { ...@@ -532,6 +532,7 @@ class AndroidViewController {
await SystemChannels.platform_views.invokeMethod<void>('dispose', id); await SystemChannels.platform_views.invokeMethod<void>('dispose', id);
_platformViewCreatedCallbacks.clear(); _platformViewCreatedCallbacks.clear();
_state = _AndroidViewState.disposed; _state = _AndroidViewState.disposed;
PlatformViewsService._instance._focusCallbacks.remove(id);
} }
/// Sizes the Android View. /// Sizes the Android View.
......
...@@ -85,6 +85,23 @@ void main() { ...@@ -85,6 +85,23 @@ void main() {
await viewController.dispose(); await viewController.dispose();
}); });
test('dispose clears focusCallbacks', () async {
bool didFocus = false;
viewsController.registerViewType('webview');
final AndroidViewController viewController = PlatformViewsService.initAndroidView(
id: 0,
viewType: 'webview',
layoutDirection: TextDirection.ltr,
onFocus: () { didFocus = true; }
);
await viewController.setSize(const Size(100.0, 100.0));
await viewController.dispose();
final ByteData message =
SystemChannels.platform_views.codec.encodeMethodCall(const MethodCall('viewFocused', 0));
await SystemChannels.platform_views.binaryMessenger.handlePlatformMessage(SystemChannels.platform_views.name, message, (_) { });
expect(didFocus, isFalse);
});
test('resize Android view', () async { test('resize Android view', () async {
viewsController.registerViewType('webview'); viewsController.registerViewType('webview');
await PlatformViewsService.initAndroidView( await PlatformViewsService.initAndroidView(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment