final ScrollController _scrollController = ScrollController();
void _scrollToTop() {
_scrollController.animateTo(0,
duration: const Duration(milliseconds: 750), curve: Curves.ease);
}
// ScrollView의 controller 속성에 추가
SingleChildScrollView(
controller: _scrollController,
...
),
// Top 버튼 in Column
Padding(
padding: const EdgeInsets.all(margin16),
child: Align(
alignment: Alignment.centerRight,
child: SizedBox(
width: 50,
height: 50,
child: MaterialButton(
onPressed: () {
_scrollToTop();
},
color: Colors.grey,
splashColor: Colors.black,
child: const Text("TOP",
style: TextStyle(
color: Colors.white,
fontSize: 16,
)),
padding: const EdgeInsets.all(8),
shape: const CircleBorder(),
),
),
),
),
댓글