【问题标题】:How to scroll down the height of the screen with a Button?如何使用按钮向下滚动屏幕高度?
【发布时间】:2020-11-19 13:14:45
【问题描述】:

我想按下按钮向下滚动,正好是当前屏幕高度。

我已经尝试过这个Flutter: Scrolling to a widget in ListView,但没有多大帮助。

我在Scaffold 中使用SingleChildScrollView()

【问题讨论】:

    标签: flutter dart scroll


    【解决方案1】:

    创建一个ScrollController

    final _controller = ScrollController();
    

    您的回电。

    void _onPressed() {
      // Get the height you want to scroll to. 
      final screenHeight = MediaQuery.of(context).size.height;
    
      // If you don't want any animation, use this: 
      _controller.jumpTo(screenHeight);
    
      // Otherwise use this: 
      _controller.animateTo(screenHeight, curve: Curves.easeOut, duration: Duration(seconds: 1));
    }
    

    你的SingleChildScrollView

    SingleChildScrollView(
      controller: _controller,
      child: ...,
    )
    

    【讨论】:

    • 在 setState 中尝试 animateTo
    • @rstrelba 在任何回调中都不需要setState
    猜你喜欢
    • 1970-01-01
    • 2019-05-03
    • 2020-09-19
    • 1970-01-01
    • 2019-10-05
    • 2017-05-28
    • 2020-12-06
    • 1970-01-01
    • 2015-01-12
    相关资源
    最近更新 更多