Flutter/Dart 如何调整Modalbottomsheet动画速度?

Flutter/Dart How to adjust Modalbottomsheet animation speed?

我阅读了这篇参考文献

https://api.flutter.dev/flutter/material/showModalBottomSheet.html

它说“可以传入 transitionAnimationController 参数来自定义模态底部的外观和行为 sheets。 transitionAnimationController 控制底部 sheet 的进入和退出动画(如果提供)。

但是,我找不到 transitionAnimationController 的任何参考,

所以我的问题是,如何使用 transitionAnimationController 调整 ModalBottomSheet 动画(我想调整的进入和退出速度)?

谢谢。

如果您使用的是 StatefulWidget,请添加 with TickerProviderStateMixin 并使用 BottomSheet.createAnimationController(this) 创建 AnimationController。然后您可以在 AnimationController 上设置 duration。在此示例中,我将持续时间设置为 3 秒。

确保在 void dispose ()

中配置 AnimationController
class MyModalBottomButton extends StatefulWidget {
  @override
  _MyModalBottomButtonState createState() => _MyModalBottomButtonState();
}

class _MyModalBottomButtonState extends State<MyModalBottomButton>
    with TickerProviderStateMixin {
  AnimationController controller;

  @override
  initState() {
    super.initState();
    controller =
        BottomSheet.createAnimationController(this);
    controller.duration = Duration(seconds: 3);
  }

  @override
  void dispose() {
    controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return TextButton(
      child: Text("Show bottom sheet"),
      onPressed: () => showModalBottomSheet(
        context: context,
        transitionAnimationController: controller,
        builder: (context) {
          return Container(
            child: Text("Your bottom sheet"),
          );
        },
      ),
    );
  }
}