How to manually trigger AsyncSnapshot error with FutureBuilder
412
Return
return Future.error("Error Info", StackTrace.fromString("StackTrace Error message"));
Author by
faithomotoso
Updated on December 20, 2022Comments
-
faithomotoso over 1 year
I'm tring to manually trigger
snapshot.hasError
when a future is called and a response is gotten. For instance I have a futureFuture<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 FutureBuildersnapshot.hasError
is still null, instead it goes tosnapshot.data
.I want to be able to trigger the error if I get a
404
message for instance.