download method

Future<List<T>?> download(
  1. dynamic callback(
    1. RequestProgress,
    2. bool
    ), {
  2. Dio? dioTestClient,
})

Implementation

Future<List<T>?> download(Function(RequestProgress, bool) callback,
    {Dio? dioTestClient}) async {
  callback(
      RequestProgress(
          resourceName: this.apiResourceName as String,
          message:
              'Downloading ${this.apiResourceName?.toLowerCase()} from the server....',
          status: '',
          percentage: 0),
      false);

  this.data = await this.fetchOnline(dioTestClient: dioTestClient);

  callback(
      RequestProgress(
          resourceName: this.apiResourceName as String,
          message:
              '${data.length} ${this.apiResourceName?.toLowerCase()} downloaded successfully',
          status: '',
          percentage: 50),
      false);

  callback(
      RequestProgress(
          resourceName: this.apiResourceName as String,
          message:
              'Saving ${data.length} ${this.apiResourceName?.toLowerCase()} into phone database...',
          status: '',
          percentage: 51),
      false);

  await this.save();

  callback(
      RequestProgress(
          resourceName: this.apiResourceName as String,
          message:
              '${data.length} ${this.apiResourceName?.toLowerCase()} successfully saved into the database',
          status: '',
          percentage: 100),
      true);

  return this.data;
}