Flutter. How to add Padding for SliverGrid
Asked Answered
O

1

16

I use CustomScrollView with SliverGrid. I add space between grid items using this: mainAxisSpacing: 8, crossAxisSpacing: 8. But is it possible to add space (margin/padding) before the first and after the last column. I tried to wrap my SliverGrid in Padding, but I get the error:

A RenderViewport expected a child of type RenderSliver but received a child of type RenderPadding.

RenderObjects expect specific types of children because they coordinate with their children during layout and paint. For example, a RenderSliver cannot be the child of a RenderBox because a RenderSliver does not understand

Please, help me how to add start and end margin of my GridView.

Occidentalize answered 21/12, 2021 at 16:32 Comment(1)
use mainAxisSpacing: 10.0, crossAxisSpacing: 10.0,Tambratamburlaine
T
48

You can use the SliverPadding class:

SliverPadding(
        padding: const EdgeInsets.symmetric(horizontal: 16),
        sliver: SliverGrid.count(
          ...
        ),
      ),
Thoroughfare answered 24/1, 2022 at 23:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.