152

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

Tobias Gubo
  • 3,029
  • 5
  • 13
  • 13
  • 41
    There is an field in ListView `physics = NeverScrollableScrollPhysics()`; Now you can implement it base on some condition – Tree May 23 '18 at 03:56
  • Can you talk more about what you've tried and what didn't work? – Edman May 23 '18 at 06:55

6 Answers6

257

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

NeverScrollableScrollPhysics class

Scroll physics that does not allow the user to scroll.

Elte Hupkes
  • 2,773
  • 2
  • 23
  • 18
Danny Tuppeny
  • 40,147
  • 24
  • 151
  • 275
250

Inside ListView widget, use

physics: const NeverScrollableScrollPhysics()
Ankur Kedia
  • 3,453
  • 1
  • 13
  • 15
49

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

Mital Joshi
  • 1,132
  • 1
  • 11
  • 15
22

Conditional statement for enable and disable scrollview.

physics: chckSwitch ? const  NeverScrollableScrollPhysics() : const AlwaysScrollableScrollPhysics(),
4b0
  • 21,981
  • 30
  • 95
  • 142
Ferer Atlus
  • 256
  • 2
  • 6
17

Worked for me

 ListView.builder(
    scrollDirection: Axis.vertical,
    shrinkWrap: true,
    physics: const ClampingScrollPhysics(),
...
Shiru99
  • 429
  • 7
  • 12
  • 3
    Hi and welcome to Stack Overflow! Please take the [tour](https://stackoverflow.com/tour). Thanks for contributing an answer but can you also add an explanation on how your code solves the problem? – Jeanne Dark Nov 29 '20 at 07:36
4

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

user2807083
  • 2,962
  • 4
  • 29
  • 37