如果列表可滚动,则显示箭头指示器



我有一个水平的SingleChildScrollView小部件,它有不同数量的按钮。只有当屏幕上有太多的按钮无法全部显示时,我才想用右箭头显示按钮。我想避免有人不知道隐藏在屏幕右边缘后面的更多按钮的情况。

如何做到这一点?

Container(
height: iconsBarHeight,
color: Theme.of(context).scaffoldBackgroundColor,
padding: const EdgeInsets.fromLTRB(16, 16, 8, 0),
child: SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Button2(),
Button4(),
Button1(),
Button6(),
Button7(),
Button3(),
Button2(),
],
),
),
);

您可以将ScrollController添加到SingleChildScrollView中,并获取其最大范围。如果最大范围大于屏幕宽度,则显示按钮。

scrollController.position.maxScrollExtent

最新更新