From 6b4a10ae533373c5b7ce8cf1dd18cf3a78fdb8ec Mon Sep 17 00:00:00 2001 From: tauu Date: Thu, 10 Oct 2019 21:27:21 +0200 Subject: [PATCH] PlatformView: recreate surface if the controller changes (#40280) Currently the surface of a platform view is only created only one when the state of PlatformViewLink is created. When the PlatformViewLink widget changes, the PlatformViewController in the corresponding state is also updated. Just the surface is not updated even though it depends on the controller. This PR changes this behavior to recreate the surface whenever the controller is updated. --- packages/flutter/lib/src/widgets/platform_view.dart | 3 +++ packages/flutter/test/widgets/platform_view_test.dart | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/packages/flutter/lib/src/widgets/platform_view.dart b/packages/flutter/lib/src/widgets/platform_view.dart index 8356982198..27b0b977dd 100644 --- a/packages/flutter/lib/src/widgets/platform_view.dart +++ b/packages/flutter/lib/src/widgets/platform_view.dart @@ -846,6 +846,9 @@ class _PlatformViewLinkState extends State { if (widget.viewType != oldWidget.viewType) { _controller?.dispose(); + // The _surface has to be recreated as its controller is disposed. + // Setting _surface to null will trigger its creation in build(). + _surface = null; // We are about to create a new platform view. _platformViewCreated = false; diff --git a/packages/flutter/test/widgets/platform_view_test.dart b/packages/flutter/test/widgets/platform_view_test.dart index cc3fd902b8..a77b5c3ff3 100644 --- a/packages/flutter/test/widgets/platform_view_test.dart +++ b/packages/flutter/test/widgets/platform_view_test.dart @@ -2059,6 +2059,7 @@ void main() { testWidgets('PlatformViewLink re-initializes when view type changes', (WidgetTester tester) async { final int currentViewId = platformViewsRegistry.getNextPlatformViewId(); final List ids = []; + final List surfaceViewIds = []; final List viewTypes = []; PlatformViewLink createPlatformViewLink(String viewType) { @@ -2072,6 +2073,7 @@ void main() { return controller; }, surfaceFactory: (BuildContext context, PlatformViewController controller) { + surfaceViewIds.add(controller.viewId); return PlatformViewSurface( gestureRecognizers: const >{}, controller: controller, @@ -2107,6 +2109,13 @@ void main() { ]), ); + expect( + surfaceViewIds, + unorderedEquals([ + currentViewId+1, currentViewId+2, + ]), + ); + expect( viewTypes, unorderedEquals([