重现步骤

无需深入研究代码,每次更改时都会触发一个动画,其中:

@override
Widget build(BuildContext context) {

    if (this._currentTime != widget.amountOfTime) {
      this._changeTimeAnimation();
    }

    return new AnimatedBuilder(
      animation: this._animation,
      builder: (BuildContext context, Widget child) => this._flipAnimation(child),
      child: new Text(
        this._currentTime,
        textAlign: TextAlign.left,
        style: new TextStyle(fontSize: 100.0),
      ),
    );
  }

而且this._flipAnimation()如下:
Transform _flipAnimation(Widget child) {
    /// Function used to generate a flip animation for the time

    final Matrix4 transform = new Matrix4.identity()
      ..scale(1.0, this._animation.value, 1.0);

    return Transform(
      transform: transform,
      alignment: FractionalOffset.center,
      child: child,
    );
  }

每次触发动画时,我都会收到消息D/skia (22985): Could not invert viewmatrix。这是为什么?

我会注意到,动画在设备上似乎工作正常,但是打印输出很奇怪。

日志

flutter run之后:
Performing full restart...
Restarted app in 2,182ms.
D/skia    (22985): Could not invert viewmatrix
D/skia    (22985): Could not invert viewmatrix
D/skia    (22985): Could not invert viewmatrix
D/skia    (22985): Could not invert viewmatrix
D/skia    (22985): Could not invert viewmatrix

flutter 医生

运行flutter doctor -v后:
[✓] Flutter (Channel beta, v0.2.8, on Mac OS X 10.13.4 17E199, locale en-US)
    • Flutter version 0.2.8 at /Users/jvanderen11/flutter
    • Framework revision b397406561 (13 days ago), 2018-04-02 13:53:20 -0700
    • Engine revision c903c217a1
    • Dart version 2.0.0-dev.43.0.flutter-52afcba357

[✓] Android toolchain - develop for Android devices (Android SDK
27.0.3)
    • Android SDK at /Users/jvanderen11/Library/Android/sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-27, build-tools 27.0.3
    • Java binary at: /Applications/Developer Tools/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)
    • All Android licenses accepted.

[✓] iOS toolchain - develop for iOS devices (Xcode 9.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 9.3, Build version 9E145
    • ios-deploy 1.9.2
    • CocoaPods version 1.5.0

[✓] Android Studio (version 3.1)
    • Android Studio at /Applications/Developer Tools/Android Studio.app/Contents
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)

[✓] IntelliJ IDEA Ultimate Edition (version 2018.1.1)
    • IntelliJ at /Users/jvanderen11/Applications/JetBrains Toolbox/IntelliJ IDEA Ultimate.app
    • Flutter plugin version 23.1.3
    • Dart plugin version 181.4203.498

[✓] Connected devices (1 available)
    • Android SDK built for x86 • emulator-5554 • android-x86 • Android 7.1.1 (API 25) (emulator)

• No issues found!

最佳答案

错误的原因是,当缩放比例为(1.0,0.0,1.0)时,它会导致Skia不喜欢的矩阵(可能无效-参见where skia generates the error,我认为是the line where it causes the error)。

一个简单的解决方法是确保您永远不会通过修改代码或每次添加少量数字即..scale(1.0, this._animation.value + smallval, 1.0)来实际通过scale(1.0,0.0,1.0)

显然smallval=1e-100太小,因为它会在向Skia转换为c++的过程中丢失,但是smallval=0.000000000000000000000000000000000000000000000001确实可以工作。

10-08 03:23