fix memory leak of android view (#50111)
This commit is contained in:
@@ -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() {
|
|||||||
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(
|
||||||
|
|||||||
Reference in New Issue
Block a user