-
Notifications
You must be signed in to change notification settings - Fork 305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
自定义的widget是否能通过调用js得到想要的Widget #1399
Comments
用 JS 就是通过 document.createElement 创建一个新的 custom element。 |
那怎么返回给这个WidgetElement呢? appendChild? |
嗯, appendChild 后,子 Element 会传递到 WidgetElement 的 build 中,chidren 参数会带上。 |
我现在是这么弄的,但是把childen放到列表里面就会有问题,滚动也有问题,感觉自定义的WidgetElement列表和KrakenElementToWidgetAdaptor不兼容。可以看我给出来的代码. 能力有限,尝试改源码滚动的时候也会报错。动态增加flutter创建出来的元素(append1替换成append2方法)是没问题的。 js代码:
dart代码: import 'package:kraken/widget.dart'; class DemoElement2 extends WidgetElement { // DemoElement2(context) : super(context, defaultStyle: {'display': 'block'}); append1(children) { append2() { @OverRide dynamic sayHi(List args) { @OverRide
} List wList = []; appendW(List w) {
} _ListWidget(index) { 异常信息: ======== Exception caught by widgets library ======================================================= Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause. The relevant error-causing widget was: |
是在最新的 main 上测试的吗?这个问题看起来最近修过,由于重复调用 insert 的缘故。 |
对的 最新的main测试的, commitid :193b7459d38daa997eea9dfb8bfae320787c5326 |
有相关的北海交流群吗?方便发一下吗? |
答疑只走 issue,群内不答疑。交流群可以在 TSC 那边找到。 |
使用场景 | Use case
自定义的widget是否能通过调用js得到想要的Widget, 目前看文档dart和js通讯好像做不到类似的
例如自定义了一个 widget, widget里面对业务逻辑的处理,但是ui需要通过调用js得到的,js根据业务数据来生成对应的ui a、b、c..等
提案 | Proposal
伪代码例子:
class DemoElement2 extends WidgetElement {
List dataList = [{"name":"1", "style":"1"}, {"name":"2", "style":"2"}, {"name":"3", "style":"3"}];
DemoElement2(context) : super(context, defaultStyle: {'display': 'block'});
@OverRide
Widget build(BuildContext context, Map<String, dynamic> properties,
List children) {
return Container(
color: Colors.blue,
width: 300,
height: 500,
child:CustomScrollView(
slivers: [SliverList(
delegate: SliverChildBuilderDelegate(
(_, index) => _ListWidget(index),
childCount: dataList.length,
)])); }
_ListWidget(index) {
// dataList[index] , 根据数据调用js,能否得到一个StyleWidget ???
return StyleWidget;
}
dynamic sayHi(List args) {
print(args);
print(args[0]);
print(args[0].runtimeType);
}
@OverRide
getBindingProperty(String key) {
if (key == 'sayHi') {
return sayHi;
}
}
}
The text was updated successfully, but these errors were encountered: