-
Notifications
You must be signed in to change notification settings - Fork 198
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
Rive texts error with font: LateInitializationError: Field '_makeFont' has not been initialized #370
Comments
This is my debug:
|
Updatethe problem arises ONLY when the Rive.assets(...) widget (containing the text) is built immediately after the initstate. Some examples:
BypassI got around the problem by modifying my UI and inserting the animation with the text later in a ListView, but this is a very limiting problem. |
Same issue here |
HACK wrapper, add asset blank.riv with transparent BG and text, then wrap your animation in this dumb component: class _RiveLoader extends StatefulWidget {
const _RiveLoader({required this.child});
final Widget child;
@override
State createState() => _RiveLoaderState();
}
class _RiveLoaderState extends State<_RiveLoader> {
static bool initialized = false;
bool init = initialized;
@override
void initState() {
super.initState();
tryLoad();
}
void tryLoad() async {
try {
await rive.FontAsset.parseBytes(Uint8List.fromList([]));
} catch (e) {
final message = e.toString();
print(message);
if (message.contains("LateInitializationError")) {
await Future.delayed(const Duration(milliseconds: 100), () {
tryLoad();
});
} else {
setState(() {
initialized = true;
init = true;
});
}
}
setState(() {
init = true;
initialized = true;
});
}
@override
Widget build(BuildContext context) {
if (init) {
return widget.child;
}
return const Center(child: rive.RiveAnimation.asset("rive/blank.riv"));
}
}
|
@jezell |
@jezell did you add a blank asset with text in there (and also in your pubspec.yaml) to load and put your animation as the child? If you don't have text in the blank asset it won't work properly. The component just forces it to load the dummy asset to warm up the wasm module, then as soon as it stops failing to be able to parse fonts it will render the child. It will throw the error once inside that component, but it should continue on and render the child when it's ready so it doesn't attempt to play the child before fonts are ready to be rendered. I should probably just put together a pull request to fix the bug. Looks like what's happening is the component kicks off some portions before the WASM module is initialized if the first thing you try to play is an animation with text in it. |
Hi all, could you try calling This should only be needed if you're manually parsing the Rive file or using If you're still running into issues please share a reproducible example with you .riv file and the code used for us to investigate. Also be sure to use the latest versions of the runtime. |
@HayesGordon seems to work here, but seems like if using RiveAnimation.network like we were it should also handle the initialization of the text engine before it displays the file. Extra step is confusing. |
Hi everyone.
I created a file on Rive that uses Texts using the "Inter" style.
In my flutter app I use a manually imported font in the pubspec.yaml file called "ProductSans" which is not present in google fonts, so I didn't import the google_fonts package into my app.
The problem arises when I run animation in my app;
During the screen building phase this error is caused: Error: LateInitializationError: Field '_makeFont' has not been initialized.
The text was updated successfully, but these errors were encountered: