如何通过单击屏幕来反转 AnimationController?
How can I reverse an AnimationController by clicking on the screen?
我正在做与本指南类似的事情:
bottom app bar with fab
我希望在单击 FloatingActionButton 以外的任何地方时关闭动画。
我能想到的唯一解决方案是用 GestureDetector 包裹 Scaffold 主体并在单击时反转动画。
问题是,屏幕是一个里面有按钮的 CustomScrollView,所以这个解决方案不起作用(因为滚动或点击这些按钮不会反转动画)。
有什么建议吗?
将脚手架主体包裹在 GestureDetector
中可以正常工作。只需将其 hit-test 行为设置为 HitTestBehavior.opaque
and wrap its child in an IgnorePointer
即可确保滚动视图和按钮不会覆盖点击行为。
Scaffold(
...
body: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () => print('tapped'),
child: IgnorePointer(
ignoring: true,
child: ...
),
),
...
)
我正在做与本指南类似的事情: bottom app bar with fab
我希望在单击 FloatingActionButton 以外的任何地方时关闭动画。
我能想到的唯一解决方案是用 GestureDetector 包裹 Scaffold 主体并在单击时反转动画。 问题是,屏幕是一个里面有按钮的 CustomScrollView,所以这个解决方案不起作用(因为滚动或点击这些按钮不会反转动画)。
有什么建议吗?
将脚手架主体包裹在 GestureDetector
中可以正常工作。只需将其 hit-test 行为设置为 HitTestBehavior.opaque
and wrap its child in an IgnorePointer
即可确保滚动视图和按钮不会覆盖点击行为。
Scaffold(
...
body: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () => print('tapped'),
child: IgnorePointer(
ignoring: true,
child: ...
),
),
...
)