Flutter: ListView disable scrolling with touchscreen
Asked Answered
T

6

157

Is it possible to let a ListView only be scrollable with the ScrollController and not with the touchscreen?

Trenatrenail answered 22/5, 2018 at 23:28 Comment(2)
There is an field in ListView physics = NeverScrollableScrollPhysics(); Now you can implement it base on some conditionGriner
Can you talk more about what you've tried and what didn't work?Transubstantiation
C
265

As mentioned in the comments, the NeverScrollableScrollPhysics class will do this:

NeverScrollableScrollPhysics class

Scroll physics that does not allow the user to scroll.

Calefactory answered 26/5, 2018 at 16:10 Comment(0)
B
260

Inside ListView widget, use

physics: const NeverScrollableScrollPhysics()
Burnette answered 16/7, 2018 at 17:27 Comment(0)
C
53

You may add just primary: false inside your ListView Widget

Defaults to matching platform conventions. Furthermore, if the primary is false, then the user cannot scroll if there is insufficient content to scroll, while if the primary is true, they can always attempt to scroll.

For more, check out Official Doc

Cohlette answered 28/8, 2019 at 6:23 Comment(0)
T
22

Conditional statement for enable and disable scrollview.

physics: chckSwitch ? const  NeverScrollableScrollPhysics() : const AlwaysScrollableScrollPhysics(),
Thrill answered 19/11, 2019 at 7:40 Comment(0)
G
19

Worked for me

 ListView.builder(
    scrollDirection: Axis.vertical,
    shrinkWrap: true,
    physics: const ClampingScrollPhysics(),
...
Gluteal answered 29/11, 2020 at 2:8 Comment(1)
Hi and welcome to Stack Overflow! Please take the tour. Thanks for contributing an answer but can you also add an explanation on how your code solves the problem?Bodoni
D
5

what about NestedScrollView ?

            bottomNavigationBar: _buildBottomAppBar(),
            body: Container(
              child: NestedScrollView(
                physics: NeverScrollableScrollPhysics(),
                controller: _scrollViewController,
                headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
                  return <Widget>[
                    buildSliverAppBar(innerBoxIsScrolled),
                  ];
                },
                body: _buildBody(context),
              ),
            ),
          );

it's working for me

Dissipation answered 18/3, 2021 at 16:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.