【问题标题】:Flutter: ListView disable scrolling with touchscreenFlutter:ListView禁用触摸屏滚动
【发布时间】:2018-11-01 19:40:34
【问题描述】:

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

【问题讨论】:

  • ListView中有一个字段physics = NeverScrollableScrollPhysics();现在您可以根据某些条件实现它
  • 你能多谈谈你尝试过的和没用的吗?

标签: dart flutter


【解决方案1】:

如 cmets 中所述,NeverScrollableScrollPhysics class 将执行此操作:

NeverScrollableScrollPhysics 类

不允许用户滚动的滚动物理特性。

【讨论】:

  • 非常感谢,它帮助了我并节省了我的时间。
【解决方案2】:

在 ListView 小部件中,使用

physics: const NeverScrollableScrollPhysics()

【讨论】:

    【解决方案3】:

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

    默认匹配平台约定。此外,如果primary为false,则如果内容不足,用户将无法滚动,而如果primary为true,则用户始终可以尝试滚动。

    更多信息,请查看Official Doc

    【讨论】:

      【解决方案4】:

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

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

      【讨论】:

        【解决方案5】:

        为我工作

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

        【讨论】:

        • 您好,欢迎来到 Stack Overflow!请拨打tour。感谢您提供答案,但您能否添加关于您的代码如何解决问题的说明?
        【解决方案6】:

        NestedScrollView 呢?

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

        它对我有用

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2016-06-12
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-12-23
          • 1970-01-01
          • 2020-02-11
          • 2016-08-24
          相关资源
          最近更新 更多