get method

  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;

    String? consentMessageId = params?["consent-message-id"];
    if (consentMessageId == null) {
      throw ("Consent message id must not empty");
    }
    params?.remove("consent-message-id");

    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()}/$consentMessageId"
              .replaceFirst(":id", id),
          params);
      Map<String, dynamic> js = json.decode(utf8.decode(response.bodyBytes));
      data = {"data": js};
    }

    super.setInnerData(data["data"]);
    this.dataSC.add(this.data);

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