【发布时间】:2019-10-12 09:35:07
【问题描述】:
请检查以下代码。无论我尝试了什么,SizeTransition 都不会在列中水平居中。我试图将 Column 包装在 Container 中,然后提供无限宽度。我试图将 SizeTransition 包装在一个中心。我试图将 SizeTransition 包装在具有中心对齐属性的容器中。我试图将它包装在一个堆栈中。我试图给容器子元素对齐中心属性等...但是它们都不起作用...
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: AnimatedBox(),
);
}
}
class AnimatedBox extends StatefulWidget {
@override
createState() => _AnimatedBoxState();
}
class _AnimatedBoxState extends State<AnimatedBox> with SingleTickerProviderStateMixin {
AnimationController _controller;
@override
void initState() {
super.initState();
_controller = AnimationController(
vsync: this,
duration: Duration(milliseconds: 400),
);
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
RaisedButton(
child: Text('animate forward'),
onPressed: () {_controller.forward();},
),
RaisedButton(
child: Text('animate reverse'),
onPressed: () {_controller.reverse();},
),
const SizedBox(height: 100.0,),
SizeTransition(
child: Container(
width: 200.0,
height: 200.0,
color: Colors.blue,
),
sizeFactor: CurvedAnimation(
curve: Curves.fastOutSlowIn,
parent: _controller,
),
),
],
);
}
}
例如,以下代码不适用于SizeTransition,但适用于ScaleTransition。我不知道SizeTransition 有什么问题。
return Container(
width: double.infinity,
child: Column(
【问题讨论】:
-
您的目标是水平/垂直居中,还是两者兼而有之?
-
@George 非常感谢您的回复。我想水平居中。我会更新这个问题。很抱歉造成混乱。
标签: flutter