mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Co-authored-by: Kevin Chisholm <kevinjchisholm@google.com> Co-authored-by: godofredoc <godofredoc@google.com>
This commit is contained in:
parent
d9111f6402
commit
6928314d50
@ -869,10 +869,10 @@ class _PlatformViewLinkState extends State<PlatformViewLink> {
|
||||
return const SizedBox.expand();
|
||||
}
|
||||
if (!_platformViewCreated) {
|
||||
// Depending on the implementation, the initial size can be used to size
|
||||
// the platform view.
|
||||
// Depending on the implementation, the first non-empty size can be used
|
||||
// to size the platform view.
|
||||
return _PlatformViewPlaceHolder(onLayout: (Size size) {
|
||||
if (controller.awaitingCreation) {
|
||||
if (controller.awaitingCreation && !size.isEmpty) {
|
||||
controller.create(size: size);
|
||||
}
|
||||
});
|
||||
|
@ -124,6 +124,9 @@ class FakeAndroidViewController implements AndroidViewController {
|
||||
@override
|
||||
Future<void> create({Size? size}) async {
|
||||
assert(!_createCalledSuccessfully);
|
||||
if (requiresSize && size != null) {
|
||||
assert(!size.isEmpty);
|
||||
}
|
||||
_createCalledSuccessfully = size != null || !requiresSize;
|
||||
}
|
||||
|
||||
|
@ -2455,6 +2455,48 @@ void main() {
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'PlatformViewLink widget should not trigger creation with an empty size',
|
||||
(WidgetTester tester) async {
|
||||
late PlatformViewController controller;
|
||||
|
||||
final Widget widget = Center(child: SizedBox(
|
||||
height: 0,
|
||||
child: PlatformViewLink(
|
||||
viewType: 'webview',
|
||||
onCreatePlatformView: (PlatformViewCreationParams params) {
|
||||
controller = FakeAndroidViewController(params.id, requiresSize: true);
|
||||
controller.create();
|
||||
// This test should be simulating one of the texture-based display
|
||||
// modes, where `create` is a no-op when not provided a size, and
|
||||
// creation is triggered via a later call to setSize, or to `create`
|
||||
// with a size.
|
||||
expect(controller.awaitingCreation, true);
|
||||
return controller;
|
||||
},
|
||||
surfaceFactory: (BuildContext context, PlatformViewController controller) {
|
||||
return PlatformViewSurface(
|
||||
gestureRecognizers: const <Factory<OneSequenceGestureRecognizer>>{},
|
||||
controller: controller,
|
||||
hitTestBehavior: PlatformViewHitTestBehavior.opaque,
|
||||
);
|
||||
},
|
||||
)
|
||||
));
|
||||
|
||||
await tester.pumpWidget(widget);
|
||||
|
||||
expect(
|
||||
tester.allWidgets.map((Widget widget) => widget.runtimeType.toString()).toList(),
|
||||
equals(<String>['Center', 'SizedBox', 'PlatformViewLink', '_PlatformViewPlaceHolder']),
|
||||
);
|
||||
|
||||
// 'create' should not have been called by PlatformViewLink, since its
|
||||
// size is empty.
|
||||
expect(controller.awaitingCreation, true);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets(
|
||||
'PlatformViewLink calls create when needed for Android texture display modes',
|
||||
(WidgetTester tester) async {
|
||||
@ -2494,6 +2536,9 @@ void main() {
|
||||
equals(<String>['PlatformViewLink', '_PlatformViewPlaceHolder']),
|
||||
);
|
||||
|
||||
// Layout should have triggered a create call. Simulate the callback
|
||||
// that the real controller would make after creation.
|
||||
expect(controller.awaitingCreation, false);
|
||||
onPlatformViewCreatedCallBack(createdPlatformViewId);
|
||||
|
||||
await tester.pump();
|
||||
@ -2504,7 +2549,6 @@ void main() {
|
||||
);
|
||||
|
||||
expect(createdPlatformViewId, currentViewId + 1);
|
||||
expect(controller.awaitingCreation, false);
|
||||
},
|
||||
);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user