[英]Flutter - AnimatedSize not animating when setting start height to MediaQuery height
I can't figure out whats wrong...我想不通出了什么问题...
When I used a static height of 0.0 AnimatedSize widget would animate.当我使用 0.0 AnimatedSize 小部件的静态高度时,它会产生动画效果。 But when i set the topLayoutHeight = MediaQuery.of(context).size.height
nothing happens.但是当我设置topLayoutHeight = MediaQuery.of(context).size.height
什么也没有发生。
Here is my code:这是我的代码:
double topLayoutHeight = 0.0;
setHeight(){
topLayoutHeight = MediaQuery.of(context).size.height - 200;
}
my widget:我的小部件:
@override
Widget build(BuildContext context) {
setHeight();
...
...
new AnimatedSize(
curve: Curves.fastOutSlowIn,
vsync: this,
child:
new ClipPath(
clipper: CustomShapeClipper(),
child: Container(
decoration: BoxDecoration(
gradient: LinearGradient(colors: [color1, color2]),
),
height: topLayoutHeight,
),
), duration: new Duration(seconds: 2),
)
...
...
new RaisedButton(
onPressed: () {
setState(() {
shrinkOnClick = false;
topLayoutHeight = 360.0;
});
},
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(
top: Radius.circular(15.0),
bottom: Radius.circular(15.0)
)),
child: new Text('Brands',
style: TextStyle(
color: Colors.white,
fontSize: 16,
fontWeight: FontWeight.bold
),
),
color: Color(0x33FFFFFF),
elevation: 0,
)
If I never do setHeight()
everything works fine.如果我从不做setHeight()
一切正常。
Why can't I set the height dynamically with MediaQuery.of(context).size.height
?为什么我不能用MediaQuery.of(context).size.height
动态设置高度?
Use didChangeDependencies
instead改用didChangeDependencies
@override
void didChangeDependencies() {
super.didChangeDependencies();
setState(() => topLayoutHeight = MediaQuery.of(context).size.height - 200);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.