init method

void init()

Implementation

void init() {
  final showCopyButton =
      (data?.response?.responseSize).byteToKiloByteDouble() < 10
          ? true
          : false;

  // overview
  _overviews = <Widget>[];
  final duration = _dateTimeUtils.milliSecondDifference(
      data?.request?.createdAt, data?.response?.createdAt);
  _overviews.add(
      ListRowWidget(name: "Method: ", value: "${data?.request?.method}"));
  _overviews.add(ListRowWidget(
      name: "Host: ",
      value: data!.request!.secure!
          ? "https://${data?.request!.server!}"
          : "http://${data?.request!.server!}"));
  _overviews.add(
      ListRowWidget(name: "Endpoint: ", value: '${data?.request?.path}'));
  _overviews.add(ListRowWidget(name: "Duration:", value: duration));
  _overviews
      .add(ListRowWidget(name: "Client:", value: '${data?.request?.client}'));
  _overviews
      .add(ListRowWidget(name: "Secure:", value: '${data?.request?.secure}'));
  _overviews.add(const ListRowWidget(space: 10));

  // request
  _requests = <Widget>[];
  _requests.add(CardItem(
      name: "Started: ",
      value: '${data?.request?.createdAt?.toDateTime}',
      showCopyButton: showCopyButton));
  _requests.add(CardItem(
      name: "Bytes sent: ",
      value: '${data?.request?.requestSize.byteToKiloByte()}',
      showCopyButton: showCopyButton));
  _requests.add(CardItem(
      name: "Header:",
      value: data?.request?.requestHeader ?? "N/A",
      showCopyButton: showCopyButton));
  _requests.add(CardItem(
      name: "Query Parameter:",
      value: data?.request?.params ?? "N/A",
      showCopyButton: showCopyButton));
  _requests.add(CardItem(
      name: "Body:",
      value: data?.request?.requestBody ?? "N/A",
      showCopyButton: showCopyButton));

  // response
  _responses = <Widget>[];
  _responses.add(const ListRowWidget(space: 8));
  _responses.add(ListRowWidget(
      name: 'Received: ', value: '${data?.response?.createdAt?.toDateTime}'));
  _responses.add(ListRowWidget(
      name: "Status Code:", value: '${data?.response?.responseStatusCode}'));
  if (data?.response?.responseSize != null) {
    _responses.add(ListRowWidget(
        name: "Bytes received:",
        value: '${data?.response?.responseSize.byteToKiloByte()}'));
  }
  _responses.add(ResponseHeaderWidget(
    headers: data?.response?.responseHeader,
  ));
  _responses.add(CardItem(
      name: "Body",
      value: data?.response?.responseBody ?? "N/A",
      showCopyButton: showCopyButton));
  _responses.add(const ListRowWidget(space: 20));

  //error
  _errors = <Widget>[];
  if (data?.error?.errorMessage != null) {
    _errors.add(CardItem(
        name: "Error: ",
        value: data?.error?.errorMessage,
        showCopyButton: showCopyButton));
  }
  notifyListeners();
}