有有一个问题
AnimatedContainer和
CupertinoPicker,因为它使用了孩子一个固定的高度
itemExtent: 40。
尝试使用
SizeTransition以达到相同的效果。这是一个示例:
class _MySampleWidgetState extends State<MySampleWidget> with SingleTickerProviderStateMixin { bool showPicker = false; AnimationController _controller; @override void initState() { _controller = AnimationController( vsync: this, duration: Duration(milliseconds: 200), ); super.initState(); } @override void dispose() { _controller.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ RaisedButton( child: Text("text"), onPressed: () { showPicker = !showPicker; if (showPicker) { _controller.forward(); } else { _controller.reverse(); } }, ), SizeTransition( sizeFactor: _controller, child: Container( height: 150, child: CupertinoPicker( backgroundColor: Colors.transparent, itemExtent: 40, children: List<Widget>.generate( 98, (index) => Center( child: Text( '${index + 2}', style: TextStyle(color: Colors.black, fontSize: 16), ), )), onSelectedItemChanged: (item) {print((item + 2).toString()); }, ), ), ), ], ), ); } }


