【发布时间】:2019-01-09 20:21:31
【问题描述】:
我正在尝试在颤振中创建此字体大小动画,但收到以下错误:getter 'value' was called on null.
这似乎很奇怪,因为我有另一个具有类似代码的 dart 文件并且它运行良好。
我们将不胜感激。
Animation<double> _fontSizeAnimation;
AnimationController _fontSizeAnimationController;
initState 函数():
super.initState();
_fontSizeAnimationController = new AnimationController(
duration: new Duration(milliseconds: 500), vsync: this);
_fontSizeAnimation = new CurvedAnimation(
parent: _fontSizeAnimationController, curve: Curves.bounceOut);
_fontSizeAnimation.addListener(() => this.setState(() {}));
_fontSizeAnimationController.forward();
材质小部件
return new Material(
color: Colors.blueAccent,
child: new InkWell(
onTap: () => print("We tapped the page!"),
child: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Text("Let's Quizzz",
style: new TextStyle(
color: Colors.white,
fontSize: _fontSizeAnimation.value * 15,
fontWeight: FontWeight.bold)),
new Text("Tap to start!",
style: new TextStyle(
color: Colors.white,
fontSize: 20.0,
fontWeight: FontWeight.bold))
],
),
),
);
【问题讨论】:
-
这意味着
_fontSizeAnimation是null whenfontSize: _fontSizeAnimation.value * 15,`被执行。从您发布的代码中很难判断为什么它是null