在儿童中添加填充物 在Flutter

问题描述 投票:0回答:2

我有一个包含一些图像的gridview。

但是你知道,它彼此如此接近,我想给他们一个其他的空间。

但我仍然无法做到。

我试着做一些实验。但它仍然没有给我任何东西。问题是填充是在gridview内部。如果我把它们(所有物品)放在1个容器,1个容器,1个容器等中,gridview中有很多容器。

`Container(
            margin: new EdgeInsets.all(2.0),
            color: Colors.red,
            padding: EdgeInsets.all(10.0),
            child: GridView.count(
              physics: NeverScrollableScrollPhysics(),
              shrinkWrap: true,
              crossAxisCount: 6,
              children: <Widget>[
                Image.asset('images/user.png', width: 30.0),
                Image.asset('images/user.png', width: 30.0),
                Image.asset('images/user.png', width: 30.0),
                Image.asset('images/user.png', width: 30.0),
                Image.asset('images/user.png', width: 30.0),
                Image.asset('images/user.png', width: 30.0),
                Image.asset('images/user.png', width: 30.0),
                Image.asset('images/user.png', width: 30.0),
                Image.asset('images/user.png', width: 30.0),
                Image.asset('images/user.png', width: 30.0),
                Image.asset('images/user.png', width: 30.0),
              ],
            ),
          ),

这里预览:https://imgur.com/ot3phXV`

flutter margin padding flutter-layout
2个回答
1
投票

gridview中相互之间的空间设置gridview的mainAxisSpacing和crossAxisSpacing属性,

GridView.count(
          physics: NeverScrollableScrollPhysics(),
          shrinkWrap: true,
          crossAxisCount: 6,
          mainAxisSpacing: 8.0,
          crossAxisSpacing: 8.0,
          children: <Widget>[
            Image.asset('images/user.png', width: 30.0),
            Image.asset('images/user.png', width: 30.0),
            Image.asset('images/user.png', width: 30.0),
            Image.asset('images/user.png', width: 30.0),
            Image.asset('images/user.png', width: 30.0),
            Image.asset('images/user.png', width: 30.0),
            Image.asset('images/user.png', width: 30.0),
            Image.asset('images/user.png', width: 30.0),
            Image.asset('images/user.png', width: 30.0),
            Image.asset('images/user.png', width: 30.0),
            Image.asset('images/user.png', width: 30.0),
          ],
        ),

1
投票

您可以在孩子之间添加SizedBox

SizedBox(
  width: 200.0,
  height: 300.0,
)

您的代码可以编辑成

Container(
    margin: new EdgeInsets.all(2.0),
    color: Colors.red,
    padding: EdgeInsets.all(10.0),
    child: GridView.count(
      physics: NeverScrollableScrollPhysics(),
      shrinkWrap: true,
      crossAxisCount: 6,
      children: <Widget>[
        Image.asset('images/user.png', width: 30.0),
        SizedBox(width: 10,height: 10,),
        Image.asset('images/user.png', width: 30.0),
        SizedBox(width: 10,height: 10,),
        Image.asset('images/user.png', width: 30.0),
        SizedBox(width: 10,height: 10,),
        Image.asset('images/user.png', width: 30.0),
        SizedBox(width: 10,height: 10,),
        Image.asset('images/user.png', width: 30.0),
        SizedBox(width: 10,height: 10,),
        Image.asset('images/user.png', width: 30.0),
        SizedBox(width: 10,height: 10,),
        Image.asset('images/user.png', width: 30.0),
        SizedBox(width: 10,height: 10,),
        Image.asset('images/user.png', width: 30.0),
        SizedBox(width: 10,height: 10,),
        Image.asset('images/user.png', width: 30.0),
        SizedBox(width: 10,height: 10,),
        Image.asset('images/user.png', width: 30.0),
        SizedBox(width: 10,height: 10,),
        Image.asset('images/user.png', width: 30.0),
      ],
    ),
  ),
© www.soinside.com 2019 - 2024. All rights reserved.