jamesblasco / modal_bottom_sheet

Flutter | Create advanced modal bottom sheets. Material, Cupertino or your own style
https://pub.dev/packages/modal_bottom_sheet
MIT License
1.89k stars 474 forks source link

NestedScrollView reverse: scroll view length and additional grey space #167

Open pmi-luf opened 3 years ago

pmi-luf commented 3 years ago

Hello,

I have some trouble setting up the NestedScrollView with the reverse option set to true. as you can see in the screenshot if I set the reverse to true the scroll view goes up (blue rectangle) as expected but it doesn't fill the available space. I'd like to get rid of the grey space (red rectangle).

18-05-_2021_14-04-48

Here is the code of the nested view implementation:

return NestedScrollView(
      controller: ScrollController(),
      physics: ScrollPhysics(parent: PageScrollPhysics()),
      reverse: true,
      headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
        return <Widget>[
          SliverList(
            delegate: SliverChildListDelegate(
              [
                Container(height: 100, color: Colors.blue),
                Container(height: 100, color: Colors.red),
                Container(height: 100, color: Colors.yellow),
              ],
            ),
          ),
        ];
      },
      body: ListView.builder(
        controller: ModalScrollController.of(context),
        itemBuilder: (context, index) {
          return Container(
            height: 100,
            color: index.isOdd ? Colors.green : Colors.orange,
          );
        },
        itemCount: 12,
      ),
    );

Here is how I show the bottom sheet modal:

onPressed: () => showCupertinoModalBottomSheet(
    expand: true,
    context: context,
    builder: (context) => MessageComposeAttachmentsManager(),
  ),

I don't know if I'm missing something, I couldn't find any user reporting this issue. What am I doing wrong?

DaleLaw commented 2 years ago

I found a solution that is use ClampingScrollPhysics() for any sub scrollview in the NestedScrollView:

return NestedScrollView(
      controller: ScrollController(),
      physics: ScrollPhysics(parent: PageScrollPhysics()),
      reverse: true,
      headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
        return <Widget>[
          SliverList(
            delegate: SliverChildListDelegate(
              [
                Container(height: 100, color: Colors.blue),
                Container(height: 100, color: Colors.red),
                Container(height: 100, color: Colors.yellow),
              ],
            ),
          ),
        ];
      },
      body: ListView.builder(
        physics: ClampingScrollPhysics(), // Use ClampingScrollPhysics to prevent over scroll, thus eliminating the spaces
        controller: ModalScrollController.of(context),
        itemBuilder: (context, index) {
          return Container(
            height: 100,
            color: index.isOdd ? Colors.green : Colors.orange,
          );
        },
        itemCount: 12,
      ),
    );