postData<T> method

Future<T> postData<T>({
  1. required String path,
  2. required T builder(
    1. dynamic data
    ),
  3. Options? options,
  4. FormData? formData,
})

Implementation

Future<T> postData<T>({
  required String path,
  required T Function(dynamic data) builder,
  Options? options,
  FormData? formData,
}) async {
  try {
    var reponse =
        await dio.post(path, options: options ?? _options, data: formData);
    switch (reponse.statusCode) {
      case 200:
        // var data = json.decode(reponse.data);
        return builder(reponse.data);
      case 401:
        throw const APIError.invalidApiKey();
      case 404:
        throw const APIError.notFound();
      default:
        throw const APIError.unknown();
    }
  } on SocketException catch (_) {
    throw const APIError.noInternetConnection();
  }
}