Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandled Exception: Exception: LateInitializationError: Field '_paint@235459774' has not been initialized #312

Open
tnaseem opened this issue Aug 16, 2021 · 2 comments

Comments

@tnaseem
Copy link

tnaseem commented Aug 16, 2021

I'm having the same issue as @azhansy here on this closed issue.

I've just updated my app from Flutter 1.x.x to 2.x.x and using flare_flutter 3.0.2.

Everything was working fine under Flutter 1.x.x, but since upgrading my code to work with 2.2.3, this is the only problem I'm experiencing in my app. The error output is:

[VERBOSE-2:ui_dart_state.cc(199)] Unhandled Exception: Exception: LateInitializationError: Field '_paint@235459774' has not been initialized.
#0      FlutterActorImage._paint (package:flare_flutter/flare.dart)
#1      FlutterActorImage.onBlendModeChanged (package:flare_flutter/flare.dart:505:5)
#2      FlutterActorDrawable.blendMode= (package:flare_flutter/flare.dart:226:5)
#3      FlutterActorDrawable.blendModeId= (package:flare_flutter/flare.dart:234:5)
#4      ActorDrawable.read (package:flare_flutter/base/actor_drawable.dart:77:17)
#5      ActorImage.read (package:flare_flutter/base/actor_image.dart:305:19)
#6      ActorArtboard.readComponentsBlock (package:flare_flutter/base/actor_artboard.dart:387:34)
#7      ActorArtboard.read (package:flare_flutter/base/actor_artboard.dart:349:11)
#8      Actor.readArtboardsBlock (package:flare_flutter/base/actor.dart:180:22)
#9      Actor.load (package:flare_flutter/base/actor.dart:85:11)
#10     FlutterActor.loadFromByteData (package:flare_flutter/flare.dar<…>

I created a helper class for my Flare/Rive animations as below:

class Rive {

  // Singleton
  static final Rive _instance = new Rive.internal();
  factory Rive() => _instance;
  Rive.internal();

  final Map<String, AssetFlare> _assets = {};


  // Initialise the Flare assets.
  Future<void> init() async {
    animAsset.forEach((name, filename) {
      _assets[name] = AssetFlare(bundle: rootBundle, name: filename);
    });

    // Don't prune the Flare cache, keep cached files ready to be re-displayed.
    FlareCache.doesPrune = false;
    await _cacheAssets();
  }

  // Play the named Flare animation asset.
  Widget play({
    @required String name,
    @required String animation,
    String artboard,
    FlareController controller,
    bool isPaused = false,
    Alignment alignment = Alignment.center,
    BoxFit fit = BoxFit.contain,
    bool antialias = false,
    void Function(String) callback,
  }) {
    return FlareActor.asset(_assets[name],
      animation: animation,
      artboard: artboard,
      controller: controller,
      isPaused: isPaused,
      alignment: alignment,
      fit: fit,
      antialias: antialias,
      callback: callback,
    );
  }

  // Load all the Flare assets into the cache.
  Future<void> _cacheAssets() async =>
    _assets.forEach((name, asset) async => await cachedActor(asset));

  // Load the specified Flare asset into the cache.
  Future<void> cacheAsset(String name) async => await cachedActor(_assets[name]);
}

Basically, on initialisation, I cache the flare assets so they're all ready to be animated. Then call the play() function to run the animation.

This all used to work beautifully in the past. Now, with Flutter 2.x I'm getting the above error (even if I don't cache the files and attempt to play the files directly). It appears to be that _paint is not getting initialised in flare.dart.

Any pointers/help are most appreciated!

@CarGuo
Copy link

CarGuo commented Sep 22, 2021

LateInitializationError

flutter sdk 2.5.1

[VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: Exception: LateInitializationError: Field '_paint@268459774' has not been initialized.
#0      FlutterActorImage._paint (package:flare_flutter/flare.dart)
#1      FlutterActorImage.onBlendModeChanged (package:flare_flutter/flare.dart:505:5)
#2      FlutterActorDrawable.blendMode= (package:flare_flutter/flare.dart:226:5)
#3      FlutterActorDrawable.blendModeId= (package:flare_flutter/flare.dart:234:5)
#4      ActorDrawable.read (package:flare_flutter/base/actor_drawable.dart:77:17)
#5      ActorImage.read (package:flare_flutter/base/actor_image.dart:305:19)
#6      ActorArtboard.readComponentsBlock (package:flare_flutter/base/actor_artboard.dart:387:34)
#7      ActorArtboard.read (package:flare_flutter/base/actor_artboard.dart:349:11)

@CarGuo
Copy link

CarGuo commented Sep 22, 2021

In onBlendModeChanged Function, _paint never initialized when ActorDrawable read -> set blendModeId ,but _paint sound late ui.Paint

  @override
  void onBlendModeChanged(ui.BlendMode mode) {
     _paint.blendMode = mode;
    onPaintUpdated(_paint);
  }

image

CarGuo added a commit to CarGuo/Flare-Flutter that referenced this issue Sep 23, 2021
CarGuo added a commit to CarGuo/Flare-Flutter that referenced this issue Sep 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants