Haj*_*ime 4 performance animation dart flutter flutter-showmodalbottomsheet
我读过这篇参考资料
https://api.flutter.dev/flutter/material/showModalBottomSheet.html
它说“可以传入transitionAnimationController参数来自定义模式底部表单的外观和行为。transitionAnimationController控制底部表单的进入和退出动画(如果提供)。”
但是,我找不到任何关于transitionAnimationController的参考,
所以我的问题是,如何使用transitionAnimationController调整ModalBottomSheet动画(我想调整的入口和出口速度)?
谢谢。
koh*_*kob 12
如果您使用的是 StatefulWidget,则添加with TickerProviderStateMixin并创建一个AnimationControllerwith BottomSheet.createAnimationController(this)。duration然后您可以在AnimationController 上设置。在此示例中,我将持续时间设置为 3 秒。
确保将 AnimationController 放置在void dispose ()
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"),
);
},
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9062 次 |
| 最近记录: |