-
Notifications
You must be signed in to change notification settings - Fork 226
Description
^0.14.0-dev.13
Description:
After migrating from the old RiveAnimation.asset API to the new Rive Flutter API, my previously working animation no longer displays at all. No errors, no logs, just an empty space where the animation should be.
I'm currently in the middle of the migration because our app update was rejected due to the old Rive implementation and the new Android 4KB memory guideline, and we urgently need this update to pass review. Unfortunately, the new Rive integration seems significantly more complicated, and so far nothing works.
This is the old code that worked perfectly:
rv.RiveAnimation.asset(
Assets.animations.birthChartAnimation,
animations: const ['Timeline 1'],
alignment: Alignment.center,
fit: BoxFit.cover,
)
I tried two different approaches based on the new API.
Both compile without errors, but neither displays anything.
Attempt 1:
import 'package:flutter/material.dart';
import 'package:rive/rive.dart';
class SimpleAssetAnimation extends StatefulWidget {
final String assetPath;
final Fit fit;
final Alignment? alignment;
const SimpleAssetAnimation({
Key? key,
required this.assetPath,
required this.fit,
this.alignment,
}) : super(key: key);
@override
State<SimpleAssetAnimation> createState() => _SimpleAssetAnimationState();
}
class _SimpleAssetAnimationState extends State<SimpleAssetAnimation> {
File? file;
RiveWidgetController? controller;
bool isInitialized = false;
@override
void initState() {
super.initState();
initRive();
}
void initRive() async {
file = (await File.asset(widget.assetPath, riveFactory: Factory.rive))!;
controller = RiveWidgetController(file!);
setState(() => isInitialized = true);
}
@override
void dispose() {
controller?.dispose();
file?.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return isInitialized && controller != null
? RiveWidget(
controller: controller!,
fit: widget.fit,
alignment: widget.alignment ?? RiveDefaults.alignment,
)
: SizedBox.shrink();
}
}
Attempt 2:
RiveSimpleAnimationPainter(
animationName: "Timeline 1",
assetPath: Assets.animations.birthChartAnimation,
fit: rv.Fit.cover,
alignment: Alignment.center,
)
---
import 'package:flutter/material.dart';
import 'package:rive/rive.dart';
class RiveSimpleAnimationPainter extends StatefulWidget {
final String assetPath;
final Fit fit;
final Alignment? alignment;
final String animationName;
const RiveSimpleAnimationPainter({
super.key,
required this.assetPath,
required this.fit,
this.alignment,
required this.animationName,
});
@override
State<RiveSimpleAnimationPainter> createState() =>
_RiveSimpleAnimationPainterState();
}
class _RiveSimpleAnimationPainterState
extends State<RiveSimpleAnimationPainter> {
late File file;
Artboard? artboard;
late SingleAnimationPainter painter;
@override
void initState() {
super.initState();
init();
}
void init() async {
file = (await File.asset(widget.assetPath, riveFactory: Factory.rive))!;
painter = SingleAnimationPainter(
widget.animationName,
alignment: widget.alignment ?? RiveDefaults.alignment,
fit: widget.fit,
);
artboard = file.defaultArtboard();
setState(() {});
}
@override
void dispose() {
painter.dispose();
artboard?.dispose();
file.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
if (artboard == null) {
return Container();
}
return RiveArtboardWidget(artboard: artboard!, painter: painter);
}
}
The migration guide unfortunately doesn’t help with this case, and there are no errors to troubleshoot.
Any guidance on how to properly migrate simple asset animations or how to debug invisible artboards in the new Rive API would be extremely appreciated.
Thanks!