FriendInviteProgressCard constructor

FriendInviteProgressCard({
  1. Key? key,
  2. required int completedInvites,
  3. required int inviteGoal,
  4. required List<FriendInviteMilestone> milestones,
  5. required VoidCallback onInvite,
  6. required ValueChanged<String> onClaimReward,
  7. String? inviteCode,
  8. VoidCallback? onCopyInvite,
  9. String title = 'Invite Friends',
  10. String message = 'Invite friends and earn rewards together.',
  11. String inviteLabel = 'Invite Friends',
  12. String copyLabel = 'Copy Code',
  13. String? semanticLabel,
})

Implementation

FriendInviteProgressCard({
  super.key,
  required this.completedInvites,
  required this.inviteGoal,
  required this.milestones,
  required this.onInvite,
  required this.onClaimReward,
  this.inviteCode,
  this.onCopyInvite,
  this.title = 'Invite Friends',
  this.message = 'Invite friends and earn rewards together.',
  this.inviteLabel = 'Invite Friends',
  this.copyLabel = 'Copy Code',
  this.semanticLabel,
}) {
  if (completedInvites < 0 || inviteGoal <= 0) {
    throw ArgumentError(
      'completedInvites must be non-negative and inviteGoal positive',
    );
  }
  if (title.trim().isEmpty || message.trim().isEmpty) {
    throw ArgumentError('title and message must not be empty');
  }
  if (inviteLabel.trim().isEmpty || copyLabel.trim().isEmpty) {
    throw ArgumentError('action labels must not be empty');
  }
  if (inviteCode != null && inviteCode!.trim().isEmpty) {
    throw ArgumentError.value(
      inviteCode,
      'inviteCode',
      'must not be empty when provided',
    );
  }
  final ids = <String>{};
  var previous = 0;
  for (final milestone in milestones) {
    if (milestone.id.trim().isEmpty || milestone.requiredInvites <= 0) {
      throw ArgumentError.value(
        milestone,
        'milestones',
        'id and positive invite target required',
      );
    }
    if (!ids.add(milestone.id)) {
      throw ArgumentError.value(
        milestone.id,
        'milestones',
        'duplicate milestone id',
      );
    }
    if (milestone.requiredInvites <= previous) {
      throw ArgumentError.value(
        milestone.requiredInvites,
        'milestones',
        'invite thresholds must be strictly increasing',
      );
    }
    previous = milestone.requiredInvites;
  }
}