【问题标题】:How can I reverse an AnimationController by clicking on the screen?如何通过单击屏幕来反转 AnimationController?
【发布时间】:2021-01-05 13:47:26
【问题描述】:

我正在做类似于本指南的事情: bottom app bar with fab

我希望动画在单击 FloatingActionButton 以外的任何位置时关闭。

我能想到的唯一解决方案是用 GestureDetector 包裹 Scaffold 主体并在点击时反转动画。 问题是,屏幕是一个带有按钮的 CustomScrollView,所以这个解决方案不起作用(因为滚动或点击这些按钮不会反转动画)。

有什么建议吗?

【问题讨论】:

    标签: flutter dart floating-action-button flutter-animation


    【解决方案1】:

    将脚手架主体包裹在 GestureDetector 中可以正常工作。只需将其命中测试行为设置为 HitTestBehavior.opaque 并将其子元素包裹在 IgnorePointer 中,以确保滚动视图和按钮不会覆盖点击行为。

    Scaffold(
      ...
      body: GestureDetector(
        behavior: HitTestBehavior.opaque,
        onTap: () => print('tapped'),
        child: IgnorePointer(
          ignoring: true,
          child: ...
        ),
      ),
      ...
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-15
      • 1970-01-01
      • 2020-12-12
      • 1970-01-01
      相关资源
      最近更新 更多