I'm tring to manually trigger snapshot.hasError
when a future is called and a response is gotten.
For instance I have a future
Future<dynamic> getJson() {
Dio dio = Dio();
var response = dio.get("https://www.jsononline.com/posts?id=9999");
if (response.statusCode == 200) {
return response;
} else {
// return AsyncSnapshot error
}
}
I've tried return AsyncSnapshot.withError(ConnectionState.done, "An error occurred");
but in the FutureBuilder snapshot.hasError
is still null, instead it goes to snapshot.data
.
I want to be able to trigger the error if I get a 404
message for instance.
Return
return Future.error("Error Info", StackTrace.fromString("StackTrace Error message"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With