Want to return error from a Future in dart? Use the below flutter example code to return error from a Future in dart.
1 2 3 4 5 6 7 8 9 10 11 12 |
Future<List> getEvents(String customerID) async { var response = await http.get( Uri.encodeFull(...) ); if (response.statusCode == 200){ return jsonDecode(response.body); }else{ // I want to return error here throw("some arbitrary error"); // error thrown } } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.