rive-flutter
rive-flutter copied to clipboard
Rive.network() OnErrorBuilder workaround?
Rive.network() doesn't have onErrorBuilder. Is there any workaround? Thanks
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();
}
}