init method

Future init(
  1. String? accId
)

init the profile

Implementation

Future<dynamic> init(String? accId) async {
  if (initialized == true) return;

  if (accId != null) {
    accountId = accId;
  }

  var res = await client.send(
    method: "POST",
    url: MCP(
      FortniteProfile.campaign,
      accountId: accountId,
      route: "public",
    ).QueryPublicProfile,
    body: {},
  );

  created = DateTime.parse(res["profileChanges"][0]["profile"]["created"]);
  updated = DateTime.parse(res["profileChanges"][0]["profile"]["updated"]);
  serverTime = DateTime.parse(res["serverTime"]);
  rvn = res["profileChanges"][0]["profile"]["rvn"];
  Map<String, dynamic> _items = res["profileChanges"][0]["profile"]["items"];
  stats = res["profileChanges"][0]["profile"]["stats"]["attributes"];

  for (var item in _items.entries) {
    switch (item.value["templateId"].toString().split(":")[0]) {
      case "AccountResource":
        items.add(
          AccountResource(
            client,
            id: item.key,
            profileId: profileId,
            templateId: item.value["templateId"],
            attributes: item.value["attributes"],
            quantity: item.value["quantity"],
          ),
        );
        break;

      case "Hero":
        items.add(
          STWHero(
            client,
            id: item.key,
            profileId: profileId,
            templateId: item.value["templateId"],
            attributes: item.value["attributes"],
            quantity: item.value["quantity"],
          ),
        );
        break;

      case "Worker":
        items.add(
          STWWorker(
            client,
            id: item.key,
            profileId: profileId,
            templateId: item.value["templateId"],
            attributes: item.value["attributes"],
            quantity: item.value["quantity"],
          ),
        );
        break;

      case "Schematic":
        items.add(
          STWSchematic(
            client,
            id: item.key,
            profileId: profileId,
            templateId: item.value["templateId"],
            attributes: item.value["attributes"],
            quantity: item.value["quantity"],
          ),
        );
        break;

      default:
        // print(item.value["templateId"]);
        items.add(
          ProfileItem(
            client,
            id: item.key,
            profileId: profileId,
            templateId: item.value["templateId"],
            attributes: item.value["attributes"],
            quantity: item.value["quantity"],
          ),
        );
        break;
    }
  }

  initialized = true;
  client.log(
      LogLevel.info, "Campaign profile module initialized [$accountId]");
}