如何解决小部件库捕获的异常 Flutter 中 ParentDataWidget 的错误使用
我收到此错误。我读到这个错误的问题是 Expanded
以及将它与 column
、row
或 flex
一起使用的解决方案。但是在我的代码中,我是这样使用的,所以应该没有错误。请帮帮我。
我的代码:
List<DataColumn> initHeader() {
List<DataColumn> header = [];
for (var i = 0; i < widget.headerList.length; i++) {
header.add(new DataColumn(
label: Flexible(
child: Text(
widget.headerList[i].name,),)));
}
return header;
}
错误:
解决方法
让我们使用此代码,它将解决您的问题
Widget build(BuildContext context) {
return Scaffold(
body: Form(
key: _formKey,child: Column(
crossAxisAlignment: CrossAxisAlignment.start,children: <Widget>[
TextFormField(
//ontroller: skuController,textInputAction: TextInputAction.done,decoration: InputDecoration(
//labelText: AppLocalizations.instance.text('Scan'),suffixIcon: IconButton(
onPressed: () {},icon: Icon(Icons.search),),//ableReport(this.getProduct()),Row(
children: <Widget>[
Expanded(
child: Padding(
padding: const EdgeInsets.only(top: 25),child: ElevatedButton(
onPressed: () {},child: Text('Submit'),)),Expanded(
child: Padding(
padding: const EdgeInsets.only(top: 25),child: Text(
'Check items',textAlign: TextAlign.center,],));
}
}
,
我将 Flexible
更改为 Container
并且运行良好且没有错误。
之前:
List<DataColumn> initHeader() {
List<DataColumn> header = [];
for (var i = 0; i < widget.headerList.length; i++) {
header.add(new DataColumn(
label: Flexible(
child: Text(
widget.headerList[i].name,)));
}
return header;
}
之后:
List<DataColumn> initHeader() {
List<DataColumn> header = [];
for (var i = 0; i < widget.headerList.length; i++) {
header.add(new DataColumn(
label: Container(
child: Text(
widget.headerList[i].name,)));
}
return header;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。