Tobias Gubo
Tobias Gubo

Reputation: 3229

Flutter: ListView disable scrolling with touchscreen

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

Upvotes: 161

Views: 175126

Answers (6)

Danny Tuppeny
Danny Tuppeny

Reputation: 42423

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

NeverScrollableScrollPhysics class

Scroll physics that does not allow the user to scroll.

Upvotes: 272

Thinh Nguyen
Thinh Nguyen

Reputation: 51

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

Upvotes: 5

Shiru99
Shiru99

Reputation: 459

Worked for me

 ListView.builder(
    scrollDirection: Axis.vertical,
    shrinkWrap: true,
    physics: const ClampingScrollPhysics(),
...

Upvotes: 20

Ferer Atlus
Ferer Atlus

Reputation: 288

Conditional statement for enable and disable scrollview.

physics: chckSwitch ? const  NeverScrollableScrollPhysics() : const AlwaysScrollableScrollPhysics(),

Upvotes: 22

Mital Joshi
Mital Joshi

Reputation: 1202

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

Upvotes: 56

Ankur Kedia
Ankur Kedia

Reputation: 3873

Inside ListView widget, use

physics: const NeverScrollableScrollPhysics()

Upvotes: 273

Related Questions