Commit 6b4a10ae authored by tauu's avatar tauu Committed by Amir Hardon

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.
parent 75f75463
...@@ -846,6 +846,9 @@ class _PlatformViewLinkState extends State<PlatformViewLink> { ...@@ -846,6 +846,9 @@ class _PlatformViewLinkState extends State<PlatformViewLink> {
if (widget.viewType != oldWidget.viewType) { if (widget.viewType != oldWidget.viewType) {
_controller?.dispose(); _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. // We are about to create a new platform view.
_platformViewCreated = false; _platformViewCreated = false;
......
...@@ -2059,6 +2059,7 @@ void main() { ...@@ -2059,6 +2059,7 @@ void main() {
testWidgets('PlatformViewLink re-initializes when view type changes', (WidgetTester tester) async { testWidgets('PlatformViewLink re-initializes when view type changes', (WidgetTester tester) async {
final int currentViewId = platformViewsRegistry.getNextPlatformViewId(); final int currentViewId = platformViewsRegistry.getNextPlatformViewId();
final List<int> ids = <int>[]; final List<int> ids = <int>[];
final List<int> surfaceViewIds = <int>[];
final List<String> viewTypes = <String>[]; final List<String> viewTypes = <String>[];
PlatformViewLink createPlatformViewLink(String viewType) { PlatformViewLink createPlatformViewLink(String viewType) {
...@@ -2072,6 +2073,7 @@ void main() { ...@@ -2072,6 +2073,7 @@ void main() {
return controller; return controller;
}, },
surfaceFactory: (BuildContext context, PlatformViewController controller) { surfaceFactory: (BuildContext context, PlatformViewController controller) {
surfaceViewIds.add(controller.viewId);
return PlatformViewSurface( return PlatformViewSurface(
gestureRecognizers: const <Factory<OneSequenceGestureRecognizer>>{}, gestureRecognizers: const <Factory<OneSequenceGestureRecognizer>>{},
controller: controller, controller: controller,
...@@ -2107,6 +2109,13 @@ void main() { ...@@ -2107,6 +2109,13 @@ void main() {
]), ]),
); );
expect(
surfaceViewIds,
unorderedEquals(<int>[
currentViewId+1, currentViewId+2,
]),
);
expect( expect(
viewTypes, viewTypes,
unorderedEquals(<String>[ unorderedEquals(<String>[
......
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