tldr; gridview 被隔开。弄得我自己想把它弄紧。需要帮忙。
问题:我正在使用 GridView.builder 来显示一些缩略图。问题是它们的间距是均匀的,而 crossAxisSpacing 也不能让它们靠得更近。到目前为止,我完全迷失了摆弄选项和随机添加灵活、包装和诸如此类的小部件。我需要帮助思考这个问题。我会先给你们所有的代码,然后是截图。非常感谢任何帮助!
构建器的代码:
class LookbackGridView extends StatelessWidget {
const LookbackGridView({Key? key}) : super(key: key);
//simplified; deleted setup for variables like gridWith etc.
return Flexible(
child: SizedBox(
width: gridWidth,
height: gridheight,
child: GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 4,
mainAxisSpacing: gridheight * 0.015,
crossAxisSpacing: gridWidth * 0.0,
),
padding: EdgeInsets.symmetric(
horizontal: 0,
),
physics: const BouncingScrollPhysics(
parent: AlwaysScrollableScrollPhysics()),
itemCount:
Provider.of<MainElementList>(context).mainElementList.length -
1,
shrinkWrap: true,
//
itemBuilder: (context, index) {
return index == 0
? SizedBox()
: HistoryThumb(
index: index,
usedFrom: 'lookbackScreen',
);
正在构建的代码:
class HistoryThumb extends StatelessWidget {
late int index;
late String usedFrom;
HistoryThumb({
required this.index,
required this.usedFrom,
Key? key,
}) : super(key: key);
@override
Widget build(BuildContext context) {
//leaving out some setup
return Column(
children: [
Text(//irrelevant),
//
SizedBox(
height: mainElementSize * 0.003,
),
GestureDetector(
onTap: () {//irrelevant)
//
},
child: ClipRRect(
borderRadius: BorderRadius.circular(5),
child: Container( //!!!this is what gives each element its size
padding: EdgeInsets.all(0),
height: historyThumbSize,
width: historyThumbSize,
//
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
HistoryThumbTask(//irrelevant),
HistoryThumbTask(//irrelevant),
],
),
//
HistoryThumbTask(//irrelevant),
//
],
截图: