fetchAfterId method Null safety

  1. @override
Future<void> fetchAfterId(
  1. String afterId,
  2. {Map<String, dynamic>? params,
  3. bool isMock = false}
)
override

Implementation

@override
Future<void> fetchAfterId(String afterId,
    {Map<String, dynamic>? params, bool isMock = false}) async {
  try {
    this.toLoadingStatus();
    late Map<String, dynamic> data;

    if (params == null) {
      params = {};
    }

    if (isMock) {
      await TimeHelper.sleep();
      data = {"items": this.options.getMockItems()?.sublist(0, 6)};
    } else {
      Response response =
          await Requester.get(this.options.getBaseUrl(), params);
      Map<String, dynamic> js = json.decode(utf8.decode(response.bodyBytes));
      data = js;
    }

    this._items = [
      ...(this._items ?? []),
      ...(data["items"] ?? []),
    ];
    this.itemsSC.add(this.items);

    this.toLoadedStatus();
  } catch (e) {
    this.alertError(e);
    this.toErrorStatus(e);
  }
}