如何使用 Button 向下滚动屏幕的高度?
How to scroll down the height of the screen with a Button?
我想通过按下按钮向下滚动,正好是当前屏幕高度。
我已经试过了,但没什么用。
我在 Scaffold
中使用 SingleChildScrollView()
。
创建 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: ...,
)
我想通过按下按钮向下滚动,正好是当前屏幕高度。
我已经试过了
我在 Scaffold
中使用 SingleChildScrollView()
。
创建 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: ...,
)