【发布时间】:2018-08-27 10:21:06
【问题描述】:
这是我的文件,但 Gridview 无法正常工作,它只显示一个错误...
我正在为列使用多个子级,并且需要在此处使用 gridview builder。
此外,我尝试使用 Stack 并删除了该列,它确实有效,但在这种情况下,我需要为每个部分使用大量填充,而这毫无价值。
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBarComponent(),
drawer: new Drawer(child: DrawerList()),
body: Container(
color: Colors.black12.withOpacity(0.02),
child: Column(
children: <Widget>[
Container(
child: Row(
children: <Widget>[
Form(
key: formKey,
child: Container(
width: 280.0,
height: 40.0,
child: TextFormField(
onSaved: (val) => keyword = val,
validator: this._validateKeyword,
decoration: new InputDecoration(
hintText: "Search Product",
fillColor: Colors.white,
filled: true,
contentPadding: new EdgeInsets.all(12.0),
),
),
),
),
ButtonTheme(
minWidth: 6.0,
height: 40.0,
child: RaisedButton(
color: Colors.redAccent.withOpacity(0.9),
onPressed: _search,
child: Icon(Icons.search,color:Colors.white,size: 26.0),
),
),
],
),
),
Padding(padding: new EdgeInsets.only(top: 12.0)),
Container(
color: Colors.white,
height: 40.0,
child: Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Icon(Icons.assignment_turned_in,color: Colors.greenAccent,),
Padding(
padding: const EdgeInsets.only(left: 4.0,right: 8.0),
child: Text("SEARCH RESULT",style: TextStyle(fontSize:14.0,fontWeight: FontWeight.w500),),
),
Padding(padding: EdgeInsets.only(left: 12.0)),
ButtonTheme(
height: 24.0,
child: RaisedButton(
padding: const EdgeInsets.all(6.0),
onPressed:()=>print("a"),
child: new Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(right: 6.0),
child: Icon(Icons.filter,size: 16.0,),
),
Text('FILTER',style: TextStyle(fontSize: 12.0),),
],
),
),
),
Padding(padding: EdgeInsets.only(left: 10.0)),
ButtonTheme(
height: 24.0,
child: RaisedButton(
onPressed:()=>print("a"),
padding: const EdgeInsets.all(6.0),
child: new Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(right: 6.0),
child: Text('SORT BY',style: TextStyle(fontSize: 12.0),),
),
Icon(Icons.keyboard_arrow_down,size: 16.0,),
],
),
),
),
],
),
),
Expanded(
child: new GridView.builder(
itemCount: 10,
gridDelegate: new SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2),
itemBuilder: (BuildContext context, int index) {
return Container(
child: Card(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 8.0),
child: Image.asset('images/product-1.png',width: 100.0),
),
Container(
color: Colors.black12.withOpacity(0.02),
height: 55.0,
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.only(left: 4.0),
child: Container(
child: Text("It is a long established fact that a readerIt is a long established fact that a reader.",
overflow: TextOverflow.ellipsis,
style: TextStyle(fontSize: 14.0)),
),
),
Padding(
padding: const EdgeInsets.only(top:8.0,left: 4.0),
child: Row(
children: <Widget>[
Text("\$57 ",style: TextStyle(fontSize:12.0,color: Colors.red,fontWeight: FontWeight.bold),),
Text(" \$57",style: TextStyle(fontSize:12.0,decoration: TextDecoration.lineThrough),),
Padding(
padding: const EdgeInsets.only(left: 4.0),
child: ButtonTheme(
minWidth: 8.0,
height: 8.0,
child: RaisedButton(
color: Colors.white.withOpacity(0.9),
onPressed: null,
child: Icon(Icons.shopping_cart,size: 18.0),
),
),
),
Padding(
padding: const EdgeInsets.only(left: 1.0),
child: ButtonTheme(
minWidth: 8.0,
height: 8.0,
child: RaisedButton(
color: Colors.white.withOpacity(0.9),
onPressed: null,
child: Icon(Icons.favorite,size: 18.0),
),
),
),
],
),
)
],
),
),
],
),
),
);
},
),
),
],
),
)
);
}
【问题讨论】:
-
请包括您得到的错误
-
我上周遇到了这个问题,并通过使用扩展的小部件解决了。看起来你用过它,当我检查我设备上的代码时,它工作得很好。请你添加你得到的错误,好吗?
-
您的代码运行良好。你能添加错误吗??
标签: gridview material-design flutter multiple-columns