颤动:ListView禁用触摸屏滚动

Tob*_*ubo 33 dart flutter

是否可以让ListView只能用ScrollController而不是触摸屏滚动?

Dan*_*eny 61

正如评论中所提到的,NeverScrollableScrollPhysics类将执行此操作:

NeverScrollableScrollPhysics类

滚动物理,不允许用户滚动.


Ank*_*dia 45

在ListView小部件中,使用

physics: const NeverScrollableScrollPhysics()
Run Code Online (Sandbox Code Playgroud)


Mit*_*shi 37

您可以primary: false在 ListView 小部件内添加

默认为匹配平台约定。此外,如果primary 为false,那么如果没有足够的内容可以滚动,用户将无法滚动,而如果primary 为true,他们总是可以尝试滚动。

更多内容请查看官方文档


Fer*_*lus 13

启用和禁用滚动视图的条件语句。

physics: chckSwitch ? const  NeverScrollableScrollPhysics() : const AlwaysScrollableScrollPhysics(),
Run Code Online (Sandbox Code Playgroud)


小智 5

为我工作

 ListView.builder(
    scrollDirection: Axis.vertical,
    shrinkWrap: true,
    physics: const ClampingScrollPhysics(),
...
Run Code Online (Sandbox Code Playgroud)

  • 您好,欢迎来到 Stack Overflow!请参加[游览](https://stackoverflow.com/tour)。感谢您提供答案,但您能否添加有关您的代码如何解决问题的解释? (2认同)

小智 5

NestedScrollView 怎么样?

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

它对我有用