GuildContributionCard constructor
GuildContributionCard({
- Key? key,
- required String guildName,
- required String goalTitle,
- required int totalContribution,
- required int goalContribution,
- required int memberContribution,
- required List<
GuildContributionMilestone> milestones, - required VoidCallback onContribute,
- required ValueChanged<
String> onClaimMilestone, - bool isLoading = false,
- String? errorMessage,
- Future<
void> onRetry()?, - String contributeLabel = 'Contribute',
- 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;
}
}