flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
166.34k stars 27.53k forks source link

Why can't I set the background color and margin of SliverGrid? #134122

Closed giantss closed 1 year ago

giantss commented 1 year ago

Is there an existing issue for this?

Use case

When I used CustomScrollView SliverGrid, I found that the background color and margins could not be set separately for SliverGrid. I think this is a very common function, and I found that many developers have encountered similar problems. May I ask if the official plans to add relevant attributes?

Proposal

image

I have used CustomScrollView to realize almost all the effects in the picture above, but SliverGrid cannot set the background color and margins. I have tried various methods and finally failed to achieve it, so I had to give up this component in the end.

farhanfadila1717 commented 1 year ago

@giantss you can add margin and backgroundColor in Sliver widget, you need sliver_tools package for get widget SliverStack. Example:

SliverStack(
      insetOnOverlap: false, // defaults to false
      children: <Widget>[
        // add background color
        SliverPositioned.fill(
          child: Container(
            decoration: BoxDecoration(
              color: Colors.amber,
            ),
          ),
        ),
        SliverPadding(
            // add margin 
            padding: EdgeInsets.all(20),
            sliver: SliverGrid()
         ),
      ],
    );
dam-ease commented 1 year ago

Thanks for your input @farhanfadila1717. Hi @giantss. Thanks for proposing this! Can you try out https://github.com/flutter/flutter/issues/134122#issuecomment-1708381799 to see if it suits your use case?

giantss commented 1 year ago

Thanks @farhanfadila1717.

github-actions[bot] commented 1 year ago

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.