Flutter app freezes when using Rive with Factory.rive, device overheats with Factory.flutter

Hello everyone,

I would like to ask for help with an issue we have been facing since Flutter 3.38.

When using our rives, we used to keep the riveFactory parameters set to Factory.rive, but after some time, the app freezes while the animation is running

To try to fix this issue, I changed the riveFactory to Factory.flutter. This seemed to solve the freezing issue, but then the device started overheating.

I’m not sure whether this issue is related to our Rive files not being fully optimized or to our implementation.

I’m attaching the class where the Rive files are loaded:

class RiveAnimationWidget extends StatefulWidget {
  const RiveAnimationWidget(
    this.asset, {
    super.key,
    this.fit,
    this.onInit,
    this.onControllerInit,
    this.alignment,
    this.animations = const [],
    this.stateMachines = const [],
  });
  final String asset;
  final BoxFit? fit;
  final Alignment? alignment;
  final void Function(Artboard)? onInit;
  final void Function(RiveWidgetController)? onControllerInit;
  final List<String> animations;
  final List<String> stateMachines;

  @override
  State<RiveAnimationWidget> createState() => _RiveAnimationWidgetState();
}

class _RiveAnimationWidgetState extends State<RiveAnimationWidget> {
  late FileLoader _fileLoader;

  @override
  void initState() {
    super.initState();
    _fileLoader = FileLoader.fromAsset(widget.asset, riveFactory: Factory.rive);
  }

  @override
  void didUpdateWidget(covariant RiveAnimationWidget oldWidget) {
    super.didUpdateWidget(oldWidget);
    if (oldWidget.asset != widget.asset) {
      _fileLoader.dispose();
      _fileLoader = FileLoader.fromAsset(
        widget.asset,
        riveFactory: Factory.rive,
      );
    }
  }

  @override
  void dispose() {
    _fileLoader.dispose();
    super.dispose();
  }

  static Fit _boxFitToFit(BoxFit? boxFit) {
    if (boxFit == null) return Fit.contain;
    return switch (boxFit) {
      BoxFit.contain => Fit.contain,
      BoxFit.cover => Fit.cover,
      BoxFit.fill => Fit.fill,
      BoxFit.fitWidth => Fit.fitWidth,
      BoxFit.fitHeight => Fit.fitHeight,
      BoxFit.none => Fit.none,
      BoxFit.scaleDown => Fit.scaleDown,
    };
  }

  @override
  Widget build(BuildContext context) {
    return RiveWidgetBuilder(
      fileLoader: _fileLoader,
      stateMachineSelector: widget.stateMachines.isNotEmpty
          ? StateMachineSelector.byName(widget.stateMachines.first)
          : const StateMachineDefault(),
      builder: (context, state) {
        return switch (state) {
          RiveLoading() => const Center(
            child: SizedBox(
              width: 24,
              height: 24,
              child: CircularProgressIndicator(strokeWidth: 2),
            ),
          ),
          RiveFailed() => Center(
            child: Text(
              'Failed to load animation',
              style: Theme.of(context).textTheme.bodySmall?.copyWith(
                color: Theme.of(context).colorScheme.error,
              ),
            ),
          ),
          RiveLoaded(:final controller) => () {
            widget.onInit?.call(controller.artboard);
            widget.onControllerInit?.call(controller);
            return RiveWidget(
              controller: controller,
              fit: _boxFitToFit(widget.fit),
              alignment: widget.alignment ?? Alignment.center,
            );
          }(),
        };
      },
    );
  }
}

I also tried stopping animations that were still in the widget stack but not directly visible on the screen, but that did not solve the issue.

The problem is happening in an Android S25.