request<T> method

Future<APIResponse<T>> request<T>(
  1. String target,
  2. RequestType type, {
  3. Map<String, dynamic>? data,
  4. List<MultipartFile> files = const [],
  5. dynamic onFilesUpload(
    1. int bytes,
    2. int totalBytes
    )?,
  6. bool log = false,
  7. Map<String, String> headers = const {},
  8. bool appendHeader = true,
  9. dynamic onNoConnection()?,
  10. String errorsField = 'errors',
})

Implementation

Future<APIResponse<T>> request<T>(
  String target,
  RequestType type, {
  Map<String, dynamic>? data,
  List<http.MultipartFile> files = const [],
  Function(int bytes, int totalBytes)? onFilesUpload,
  bool log = false,
  Map<String, String> headers = const {},
  bool appendHeader = true,
  // Function(String reqId)? onNoConnection,
  Function()? onNoConnection,
  String errorsField = 'errors',
}) =>
    apiRequest.send(
      target,
      type,
      data: data,
      files: files,
      onFilesUpload: onFilesUpload,
      log: log,
      headers: headers,
      appendHeader: appendHeader,
      onNoConnection: () async {
        // if (cacheOnOffline) {
        //   var reqId = DateTime.now().millisecondsSinceEpoch;
        // await storageDatabase.document('api/requests').set({
        //   '$reqId': {
        //     'id': reqId,
        //     'target': target,
        //     'headers': headers,
        //     'type': type.type,
        //     'data': data,
        //   }
        // });
        // if (onNoConnection != null) onNoConnection('$reqId');
        if (onNoConnection != null) onNoConnection();
        // }
      },
      errorsField: errorsField,
    );