Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set width on Flutter SliverGrid

I'm trying display a slivergridview view and it just doesn't look good if it's always on full width especially on large screens

enter image description here

But CustomScrollView only accepts sliver widgets, which makes container & sizedbox unusable. What is your workaround on this one?

like image 212
MarkDionee B Avatar asked Oct 20 '25 07:10

MarkDionee B


1 Answers

  1. First, wrap your Scaffold body with LayoutBuilder
  2. Wrap SliverGrid with SliverPadding and set the vertical and horizontal width
    SliverPadding(
      padding: EdgeInsets.symmetric(
      vertical: 15,
      horizontal: max((constraints.maxWidth - 1200) / 2, 0) > 15 ? max((constraints.maxWidth - 1200) / 2, 0) : 15),
      sliver: SliverGrid( ...

Here's the result enter image description here

like image 183
MarkDionee B Avatar answered Oct 21 '25 23:10

MarkDionee B



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!