rive-flutter icon indicating copy to clipboard operation
rive-flutter copied to clipboard

Rive.network() OnErrorBuilder workaround?

Open irfnyas opened this issue 2 years ago • 1 comments

Rive.network() doesn't have onErrorBuilder. Is there any workaround? Thanks

irfnyas avatar Mar 01 '23 03:03 irfnyas

Hi @irfnyas, thanks for opening the issue. This is something that we will look into adding.

As a workaround you can load in the RiveFile yourself and provide it directly. And if it fails to load you can handle it in whatever way you want.

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

  @override
  State<SimpleNetworkAnimation> createState() => _SimpleNetworkAnimationState();
}

class _SimpleNetworkAnimationState extends State<SimpleNetworkAnimation> {
  @override
  void initState() {
    super.initState();
    init();
  }

  RiveFile? file;

  Future<void> init() async {
    try {
      RiveFile networkfile = await RiveFile.network(
          'https://cdn.rive.app/animations/vehicles.riv');
      setState(() {
        file = networkfile;
      });
    } on Exception {
      // TODO display error instead.
    }
  }

  @override
  Widget build(BuildContext context) {
    return file != null
        ? RiveAnimation.direct(file!)
        : const CircularProgressIndicator();
  }
}

HayesGordon avatar Mar 06 '23 10:03 HayesGordon