我正在尝试显示一个GridView,它应该填充剩余的整个空间。只有当我将它包装在SizedBox中时,gridView才能正常工作,但是当我尝试使用“扩展”包装它时,它不会显示。 我的屏幕只不过是一个脚手架而已:
body: Column(
children: <Widget>[
//recent classifications
Expanded(
child: Container(
decoration: BoxDecoration(
color: Theme.of(context).accentColor,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(30.0),
topRight: Radius.circular(30.0),
),
),
child: Column(
children: <Widget>[
CategorySelector(),
],
),
),
),
],
),
“ CategorySelector”小部件显示我的GridView:
Widget build(BuildContext context) {
return Column(
children: <Widget>[
Padding(
padding: EdgeInsets.symmetric(
horizontal: 20.0,
vertical: 0,
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
"GridView",
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
letterSpacing: 1.0,
),
),
IconButton(
icon: Icon(Icons.more_horiz),
onPressed: () {},
),
],
),
),
SizedBox(
height: 500,
child: GridView.builder(
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 20),
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: 2 / 3,
crossAxisSpacing: 20,
mainAxisSpacing: 30,
),
itemBuilder: (BuildContext context, int index) {
return Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(30),
border: Border.all(
width: 3,
color: Theme.of(context).primaryColor,
),
),
child: GridTile(
child: Image.asset(bones.bones[index].imageUrl),
footer: GridTileBar(
title: Padding(
padding: EdgeInsets.only(top: 15),
child: Text(
bones.bones[index].title,
textAlign: TextAlign.center,
style: TextStyle(
color: Theme.of(context).primaryColor,
fontWeight: FontWeight.bold,
fontSize: 18),
),
),
backgroundColor: Colors.transparent,
subtitle: Text(
bones.bones[index].id,
style: TextStyle(color: Colors.black),
),
),
),
);
},
itemCount: bones == null ? 0 : bones.bones.length,
),
),
],
);
}
在展开的窗口小部件中进行构建时,会引发以下错误:需要布局需要油漆。
我在做什么错了?