将网格视图或列表视图的最后一个奇数项水平居中我试过staggeredGridView,但它没有对齐。
r1zk6ea11#
请尝试以下代码:
SizedBox( height: h * 0.4, child: StaggeredGridView.countBuilder( crossAxisCount: 3, itemCount: 7, itemBuilder: (BuildContext context, int index) => Container( child: Center( child: Container( height: w / 4, width: w / 4, decoration: const BoxDecoration( color: Colors.green, borderRadius: BorderRadius.all(Radius.circular(10)), ), child: Center( child: Text( index == 6 ? "C" : "$index", style: const TextStyle( fontSize: 20, fontWeight: FontWeight.bold), ), ), ), )), staggeredTileBuilder: (int index) => StaggeredTile.count(index == 6 ? 3 : 1, 1), ), ),
1条答案
按热度按时间r1zk6ea11#
请尝试以下代码: