7

For ListView or GridView we wrap it with Container. But how can I give background color to SliverGrid?

CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
Figen Güngör
  • 12,169
  • 14
  • 66
  • 108

2 Answers2

3

I'll just drop my solution here. I wrap my individual items with Container and give padding.

When the last row is not complete, I just add dummy item which is a Container with bg color until row is filled.

Figen Güngör
  • 12,169
  • 14
  • 66
  • 108
1

Or you could wrap your CustomScrollView by a Container having a background color:

Container(
    color: Colors.grey[200],
    child: CustomScrollView(
      slivers: <Widget>[]
    )
)
woshitom
  • 4,811
  • 8
  • 38
  • 62
  • See this issue : https://github.com/flutter/flutter/issues/62818 Your answer gives a background to the whole CustomScrollView, not to SliverGrid. – DMonkey Sep 04 '20 at 15:21
  • this is for whole CustomScrollView, not for SliverGrid – riven Apr 09 '21 at 08:26