如果您使用 StatefulWidget 添加with TickerProviderStateMixin
并创建一个AnimationController
with 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"),
);
},
),
);
}
}