get method Null safety

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

Implementation

@override
Future<void> get(String id,
    {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 = {"data": this.options.getMockItem()};
    } else {
      Response response = await Requester.get(
          "${this.options.getFindUrl() ?? this.options.getBaseUrl()}"
              .replaceFirst(":id", id),
          params);
      Map<String, dynamic> js = json.decode(utf8.decode(response.bodyBytes));
      data = {"data": js};
    }

    this._data = data["data"];
    this.dataSC.add(this.data);

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