小部件库捕获异常。 Flutter 中 ParentDataWidget 的错误使用
Exception caught by widgets library. Incorrect use of ParentDataWidget in Flutter
我收到这个错误。我读到此错误的问题是 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: ElevatedButton(
onPressed: () {},
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;
}
我收到这个错误。我读到此错误的问题是 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: ElevatedButton(
onPressed: () {},
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;
}