【发布时间】:2019-12-22 13:01:33
【问题描述】:
我有一个 ReorderableListView 应该填充自定义小部件,但是即使在自定义无状态小部件类和构造函数中传递了键,我也会收到以下错误:
此小部件的所有子级都必须有一个键。 'package:flutter/src/material/reorderable_list.dart': 失败 断言:第 71 行 pos 10: 'children.every((Widget w) => w.key != 空)'
这是飞镖代码:
class CustomWidget extends StatelessWidget{
String CustomWidgetString;
String WidgetKey;
CustomWidget({this.CustomWidgetString, this.WidgetKey});
Widget _widget(){
return Text(
CustomWidgetString,
key: Key(WidgetKey),
);
}
@override
Widget build(BuildContext context){
return _widget();
}
}
class AppState extends State<App>{
@override
Widget build(BuildContext context){
return Scaffold(
appBar: AppBar(
title: Text("Reorderable List"),
),
body: ReorderableListView(
scrollDirection: Axis.vertical,
children: <Widget>[
CustomWidget(
CustomWidgetString: "Custom Widget",
WidgetKey: "value",
)
],
onReorder: (a, b){
},
),
);
}
}
使用颤振中可用的小部件,不要抛出任何错误。你能帮忙吗?
【问题讨论】: