79132441

Date: 2024-10-28 07:51:05
Score: 0.5
Natty:
Report link

I just got the same issue, If you are working with the StateMachineController.formArtboard

StateMachineController.fromArtboard(artboard, 'loadingState');

the name that you should enter in to the code, if you are working with the state machene

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:rive/rive.dart';

class Loader extends StatefulWidget {
  const Loader({Key? key}) : super(key: key);

  @override
  _LoaderState createState() => _LoaderState();
}

class _LoaderState extends State<Loader> {
  Artboard? _riveArtboard;
  StateMachineController? _controller;
  SMIInput<bool>? _isLoading;

  @override
  void initState() {
    super.initState();
    _loadRiveFile();
  }

  Future<void> _loadRiveFile() async {
    await RiveFile.initialize();
    final data = await rootBundle.load('assets/iconLoading.riv');
    final file = RiveFile.import(data);
    final artboard = file.mainArtboard;
    var controller = StateMachineController.fromArtboard(artboard, 'loadingState');
    if (controller != null) {
      artboard.addController(controller);
      _isLoading = controller.findInput('isLoading');
      _isLoading?.value = true;
    }
    if (mounted) {
      setState(() => _riveArtboard = artboard);
    }
  }

  void startLoading() {
    _isLoading?.value = true;
  }

  void stopLoading() {
    if (mounted) {
      setState(() {
        _isLoading?.value = false;
      });
    }
  }

  @override
  void dispose() {
    _controller?.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Center(
      child: SizedBox(
        width: 75,
        height: 75,
        child: _riveArtboard == null
            ? const CircularProgressIndicator()
            : Rive(alignment: Alignment.center, artboard: _riveArtboard!),
      ),
    );
  }
}

Always be aware about namings.

Reasons:
  • Probably link only (1):
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Ishan Lahiru