Добавить Обивка внутри Дети <Widget>во флаттере - PullRequest
0 голосов
/ 04 апреля 2019

У меня есть сетка, которая содержит несколько изображений.

, но вы знаете, это так близко друг к другу, и я хочу дать им один пробел друг от друга.

но я все еще не могу сделатьих.

Я пытаюсь провести несколько экспериментов.но это все равно не даст мне ничего.проблема в том, что отступы внутри сетки.если я помещу их (все предметы) в 1 контейнер, 1 контейнер, 1 контейнер и т. д., то внутри сетки будет много контейнеров.

`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`

Ответы [ 2 ]

1 голос
/ 04 апреля 2019

для расстояния друг к другу в gridview установите mainAxisSpacing & crossAxisSpacing свойства gridview,

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 голос
/ 04 апреля 2019

Вы можете добавить 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),
      ],
    ),
  ),
...