calcWinnings method

double calcWinnings(
  1. String contestId,
  2. bool isPast
)

Implementation

double calcWinnings(String contestId, bool isPast) {
  double winings = 0;
  List<MilestonesData> allMileStone = [];
  List<Rewards> currentContestRewards = [];
  List<ContestDataModel> data = !isPast ? _contestData : _pastContestData;

  _userData
      .where((element) => element.contestId == contestId)
      .forEach((element) {
    allMileStone.addAll(element.milestonesData as Iterable<MilestonesData>);
  });
  // log(contestId);
  currentContestRewards =
      data.where((element) => element.sId == contestId).isNotEmpty
          ? data.where((element) => element.sId == contestId).first.rewards!
          : [];
  for (int i = 0; i < currentContestRewards.length; i++) {
    bool check = false;
    for (int j = 0; j < currentContestRewards[i].milestones!.length; j++) {
      if (allMileStone
          .where((element) =>
              element.milestoneId == currentContestRewards[i].milestones![j])
          .isNotEmpty) {
        if (allMileStone
                .firstWhere((element) =>
                    element.milestoneId ==
                    currentContestRewards[i].milestones![j])
                .rewardsCredited ==
            true) {
          check = true;
        } else {
          check = false;
        }
      }
    }
    if (check) {
      winings += currentContestRewards[i].tokens![0].value ?? 0;
    }
  }
  return winings;
}