繁体   English   中英

我想让用户暂时暂停视图的滚动

[英]I'd like to enable the user to temporarily pause scrolling of the view

我的 flutter SingleChildScrollingView小部件公开实时日志并且可能变得很长。

我想为用户提供一种暂时冻结滚动条的方法,以便他可以检查日志。 完成后,他将切换回滚动。

怎么做?

return SingleChildScrollView(
  physics: BouncingScrollPhysics(),
  padding: EdgeInsets.all(contentPadding),
  child: Column(children: [
    // blah blah
  ]
);

尝试使用此演示。

定义用于管理 Scroll 的变量

 bool isScrolling = true;

滚动视图

SingleChildScrollView(
        physics: isScrolling ? const BouncingScrollPhysics() : const NeverScrollableScrollPhysics(),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text(
              'You have pushed the button this many times:',
            ),
            FloatingActionButton(
              onPressed: () {
                setState(() {
                  isScrolling = !isScrolling;
                });
              },
              tooltip: "Scroll Start And Stop",
              child: Icon(isScrolling ? Icons.play_arrow : Icons.pause),
            ),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headline4,
            ),
          ],
        ),
      ),

您可以在要滚动的位置为真,也可以为暂停屏幕设置为假。

我希望这些东西能解决你的问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM