GuildContributionCard constructor

GuildContributionCard({
  1. Key? key,
  2. required String guildName,
  3. required String goalTitle,
  4. required int totalContribution,
  5. required int goalContribution,
  6. required int memberContribution,
  7. required List<GuildContributionMilestone> milestones,
  8. required VoidCallback onContribute,
  9. required ValueChanged<String> onClaimMilestone,
  10. bool isLoading = false,
  11. String? errorMessage,
  12. Future<void> onRetry()?,
  13. String contributeLabel = 'Contribute',
  14. String title = 'Guild Goal',
})

Implementation

GuildContributionCard({
  super.key,
  required this.guildName,
  required this.goalTitle,
  required this.totalContribution,
  required this.goalContribution,
  required this.memberContribution,
  required this.milestones,
  required this.onContribute,
  required this.onClaimMilestone,
  this.isLoading = false,
  this.errorMessage,
  this.onRetry,
  this.contributeLabel = 'Contribute',
  this.title = 'Guild Goal',
}) {
  if (guildName.trim().isEmpty ||
      goalTitle.trim().isEmpty ||
      title.trim().isEmpty) {
    throw ArgumentError('guildName, goalTitle and title must not be empty');
  }
  if (totalContribution < 0 ||
      memberContribution < 0 ||
      goalContribution <= 0) {
    throw ArgumentError(
      'contribution values must be non-negative and goal positive',
    );
  }
  if (contributeLabel.trim().isEmpty) {
    throw ArgumentError.value(
      contributeLabel,
      'contributeLabel',
      'must not be empty',
    );
  }
  final ids = <String>{};
  var previous = -1;
  for (final milestone in milestones) {
    if (milestone.id.trim().isEmpty || milestone.requiredContribution <= 0) {
      throw ArgumentError.value(
        milestone,
        'milestones',
        'id and positive threshold required',
      );
    }
    if (!ids.add(milestone.id)) {
      throw ArgumentError.value(
        milestone.id,
        'milestones',
        'duplicate milestone id',
      );
    }
    if (milestone.requiredContribution <= previous) {
      throw ArgumentError.value(
        milestone.requiredContribution,
        'milestones',
        'thresholds must be strictly increasing',
      );
    }
    previous = milestone.requiredContribution;
  }
}