How do I put common logic to every Future functions?

Viewed 32

I have over 200 Future functions request rest api. ex)

Future fetchSomething(jsonData) async {
    var dio = Dio();
    try {
      var response = await dio.post(
          "serverurl",
          data: FormData.fromMap(jsonData),
          options:Options(contentType: Headers.formUrlEncodedContentType));
      return response.data;
    }
    catch (e) {
      throw Exception(e);
    }
  }

and I want the app pop modal that explain what error it is when the error occur
since I have over 200 Future functions, It's going to be hassle to put exception logic to every Future function.

Is there a way to put common logic easily?
Thank you.

0 Answers
Related