-
Notifications
You must be signed in to change notification settings - Fork 6k
[web] Support platform view creation params #42255
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's go creation params!
if (factoryFunction is ParameterizedPlatformViewFactory) { | ||
content = factoryFunction(viewId, params: params); | ||
if (factoryFunction is ui_web.ParameterizedPlatformViewFactory) { | ||
content = factoryFunction(viewId, params: params) as DomElement; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this assert(content is DomElement, 'Cool error message')
, rather than just the cast? That way we may be able to provide a better error message than the default one coming from Dart?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good idea!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I don't think DomElement
is a real type at runtime, so I'm not sure what content is DomElement
is going to check. cc @joshualitt any ideas?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to submit this as is. I can do a follow up PR if you still feel strongly about it.
expect(factoryCalls[1].viewId, 222); | ||
expect(factoryCalls[1].params, <dynamic, dynamic>{'foo': 'bar'}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need an extra case where the param passed is not a map, but a string or an int, or some other simple Object
?
…128158) flutter/engine@8769e9c...5429372 2023-06-03 [email protected] [Impeller] Fix 1-d grid computation for compute (flutter/engine#42516) 2023-06-02 [email protected] Roll Fuchsia Linux SDK from PuYA-6NVHeHPlkCdk... to VtLnfLmVda1_h1AtM... (flutter/engine#42529) 2023-06-02 [email protected] [macOS] Top-left origin for PlatformView container (flutter/engine#42523) 2023-06-02 [email protected] Manual roll Dart SDK from 9d8df2a5210b to d198f84f5e4e (1 revision) (flutter/engine#42527) 2023-06-02 [email protected] Revert "Reland "add non-rendering operation culling to DisplayListBuilder" (#41463)" (flutter/engine#42525) 2023-06-02 [email protected] Move benchmarks no upload to staging. (flutter/engine#42524) 2023-06-02 [email protected] [web] Support platform view creation params (flutter/engine#42255) 2023-06-02 [email protected] MultiView changes for dart:ui (flutter/engine#42493) Also rolling transitive DEPS: fuchsia/sdk/core/linux-amd64 from PuYA-6NVHeHP to VtLnfLmVda1_ If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
This concludes step 1 of the `HtmlElementView` improvements. It's now possible to pass creation params to platform view factories directly from `HtmlElementView`. Here's a sample app using a single factory to render platform views in different colors: <details> <summary>Code sample</summary> ```dart import 'dart:js_interop'; import 'dart:ui_web' as ui_web; import 'package:flutter/material.dart'; import 'package:web/web.dart' as web; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @OverRide Widget build(BuildContext context) { return MaterialApp( title: 'Platform View Demo', home: Scaffold( appBar: AppBar( title: Text('Platform View Demo'), ), body: Center( child: Column( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ BoxWrapper('red'), BoxWrapper(null), BoxWrapper('blue'), ], ), ), ), ); } } bool isRegistered = false; class BoxWrapper extends StatelessWidget { const BoxWrapper(this.cssColor); final String? cssColor; void register() { if (isRegistered) return; isRegistered = true; ui_web.platformViewRegistry.registerViewFactory('my-platform-view', ( id, { Object? params, }) { params as String?; final element = web.document.createElement('div'.toJS) as web.HTMLElement; element.textContent = 'Platform View'.toJS; element.style ..lineHeight = '100px'.toJS ..fontSize = '24px'.toJS ..backgroundColor = (params ?? 'pink').toJS ..textAlign = 'center'.toJS; return element; }); } @OverRide Widget build(BuildContext context) { register(); return SizedBox( width: 200, height: 100, child: Card( child: HtmlElementView( viewType: 'my-platform-view', creationParams: cssColor, ), ), ); } } ``` </details>  Depends on flutter/engine#42255 Part of #127030
creation params
in the engine.dart:ui_web
.dart:ui_web
's interface.Part of flutter/flutter#127030