问题描述
我收到此错误。我读到这个错误的问题是 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;
}