【问题标题】:The getter 'value' was called on null在 null 上调用了 getter 'value'
【发布时间】: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))
      ],
    ),
  ),
);

【问题讨论】:

  • 这意味着_fontSizeAnimationnull when fontSize: _fontSizeAnimation.value * 15,`被执行。从您发布的代码中很难判断为什么它是null

标签: dart flutter


【解决方案1】:

您可以将_fontSizeAnimation.value 合并为空

_fontSizeAnimation?.value ?? 0 * 15

【讨论】:

    【解决方案2】:

    我遇到同样的空警告。更改 _fontSizeAnimation.value 不会出现空错误...

      children: <Widget>[
        new Text("Let's Quizzz",
            style: new TextStyle(
                color: Colors.white,
                fontSize: (_fontSizeAnimation.value + 1) * 15,
                fontWeight: FontWeight.bold)),
        new Text("Tap to start!",
            style: new TextStyle(
                color: Colors.white,
                fontSize: 20.0,
                fontWeight: FontWeight.bold))
      ],
    

    【讨论】:

      猜你喜欢
      • 2020-03-24
      • 1970-01-01
      • 2018-10-22
      • 2021-12-21
      • 2020-01-10
      • 2020-10-24
      • 2021-04-13
      • 2021-10-22
      • 2020-05-20
      相关资源
      最近更新 更多