mirror of
https://github.com/flutter/flutter
synced 2024-10-13 19:52:53 +00:00
fix memory leak of android view (#50111)
This commit is contained in:
parent
e92afc16b6
commit
26fabcd41b
|
@ -532,6 +532,7 @@ class AndroidViewController {
|
|||
await SystemChannels.platform_views.invokeMethod<void>('dispose', id);
|
||||
_platformViewCreatedCallbacks.clear();
|
||||
_state = _AndroidViewState.disposed;
|
||||
PlatformViewsService._instance._focusCallbacks.remove(id);
|
||||
}
|
||||
|
||||
/// Sizes the Android View.
|
||||
|
|
|
@ -85,6 +85,23 @@ void main() {
|
|||
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 {
|
||||
viewsController.registerViewType('webview');
|
||||
await PlatformViewsService.initAndroidView(
|
||||
|
|
Loading…
Reference in a new issue