Skip to content
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.network() OnErrorBuilder workaround? #295

Open
irfnyas opened this issue Mar 1, 2023 · 1 comment
Open

Rive.network() OnErrorBuilder workaround? #295

irfnyas opened this issue Mar 1, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@irfnyas
Copy link

irfnyas commented Mar 1, 2023

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

@irfnyas irfnyas changed the title OnErrorBuilder workaround? Rive.network() OnErrorBuilder workaround? Mar 1, 2023
@HayesGordon
Copy link
Contributor

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 HayesGordon added the enhancement New feature or request label Mar 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants