【问题标题】:Animatable<Color> TweenSequence throwing error in Null SafetyAnimatable<Color> TweenSequence 在 Null 安全性中抛出错误
【发布时间】:2021-07-06 13:45:59
【问题描述】:

我刚刚在 Null Safety 中迁移了我的颤振应用。一切似乎都运行良好,除了下面的代码:

Animatable<Color> animColorPend = TweenSequence<Color>([
  TweenSequenceItem(
    weight: 1.0,
    tween: ColorTween(
      begin: Colors.purple,
      end: Colors.white,
    ) as Animatable<Color>,
  ),
  TweenSequenceItem(
    weight: 1.0,
    tween: ColorTween(
      begin: Colors.white,
      end: Colors.purple,
    ) as Animatable<Color>,
  ),
]);

演员(作为 Animatable)抛出此错误:

类型“ColorTween”不是类型转换中“Animatable”类型的子类型

以前(当我使用 --no-sound-null-safety 运行应用程序时)我没有收到此错误。这可能是一个尚未实现的错误,正如这里所说的 (https://flutter.dev/docs/null-safety)

并非 Flutter SDK 的所有部分都支持 null 安全性,因为某些部分仍需要额外的工作才能迁移到 null 安全性。

或者你认为代码中有什么东西?我尝试的一切(移除演员表、初始化 TweenSequence 而不是抽象类等等)都不起作用。感谢您的帮助!

【问题讨论】:

标签: flutter null-safety


【解决方案1】:

出于某种我不明白的原因,您必须使颜色 可为空

试试这个:

Animatable<Color> animColorPend = TweenSequence([
  TweenSequenceItem(
    weight: 1.0,
    tween: ColorTween(
      begin: Colors.purple,
      end: Colors.white,
    ) as Animatable<Color?>,
  ),
  TweenSequenceItem(
    weight: 1.0,
    tween: ColorTween(
      begin: Colors.white,
      end: Colors.purple,
    ) as Animatable<Color?>,
  ),
]);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-06-06
    • 2021-11-25
    • 2014-09-18
    • 2017-11-15
    • 1970-01-01
    • 2021-07-25
    • 1970-01-01
    相关资源
    最近更新 更多