我有一个简单的小部件,在小部件中,我有一个棕色和网格视图。问题是由于高度,它最终显示出额外的空间。如果我删除高度,则小部件不会显示。
代码
class PodcastSection extends StatelessWidget {
final String title;
final DiscoverExtended arg;
final List<Item> listOfPodcasts;
PodcastSection({@required this.title, this.arg, this.listOfPodcasts});
@override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.only(top: 18),
padding: EdgeInsets.only(left: 1, right: 1),
height: MediaQuery.of(context).size.height * 0.66,
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(color: Color(0xFF707070).withOpacity(0.35)),
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
height: MediaQuery.of(context).size.height * 0.005,
),
//TOP Row
Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
title.toUpperCase(),
style: TextStyle(
fontFamily: "Segoe UI",
fontSize: 20,
color: Colors.white,
),
),
Spacer(),
GestureDetector(
onTap: () {
Navigator.pushNamed(context, 'discover-extended',
arguments: arg);
},
child: Text(
"View all",
style: TextStyle(
fontFamily: "Product Sans",
fontSize: 15,
color: Color(0xFF969696),
),
),
)
],
),
//Podcast Item
//Podcast Item
Expanded(
child: GridView.count(
// shrinkWrap: true,
// primary: true,
physics: new NeverScrollableScrollPhysics(),
crossAxisCount: 2,
childAspectRatio: 1.1,
children: listOfPodcasts
.map<Widget>(
(e) => GestureDetector(
child: PodcastItem(podcastInfo: e),
onTap: () {
Navigator.pushNamed(context, "episode", arguments: e);
},
),
)
.toList(),
),
),
],
),
);
}
}
您可以在图像中看到其最后的显示空间
最后我需要删除额外的空间我尝试删除高度并将容器包装在扩展中,但它没有显示整个小部件行和网格。
在
GridView.count()
小部件中,有一个用于分配填充的选项。试试看:
padding: EdgeInsets.zero