UpgradePreviewPanel constructor

UpgradePreviewPanel({
  1. Key? key,
  2. required String title,
  3. required int currentLevel,
  4. required int nextLevel,
  5. required List<UpgradeStatChange> statChanges,
  6. required List<UpgradeCost> costs,
  7. required VoidCallback onUpgrade,
  8. bool isMaxLevel = false,
  9. bool isUpgrading = false,
  10. String upgradeLabel = 'Upgrade',
  11. String maxLevelLabel = 'MAX LEVEL',
  12. String? subtitle,
  13. String? semanticLabel,
})

Implementation

UpgradePreviewPanel({
  super.key,
  required this.title,
  required this.currentLevel,
  required this.nextLevel,
  required this.statChanges,
  required this.costs,
  required this.onUpgrade,
  this.isMaxLevel = false,
  this.isUpgrading = false,
  this.upgradeLabel = 'Upgrade',
  this.maxLevelLabel = 'MAX LEVEL',
  this.subtitle,
  this.semanticLabel,
}) {
  if (title.trim().isEmpty ||
      upgradeLabel.trim().isEmpty ||
      maxLevelLabel.trim().isEmpty) {
    throw ArgumentError('title and button labels must not be empty');
  }
  if (currentLevel < 0 || nextLevel <= currentLevel) {
    throw ArgumentError(
      'currentLevel must be non-negative and nextLevel higher',
    );
  }
  if (statChanges.isEmpty) {
    throw ArgumentError.value(
      statChanges,
      'statChanges',
      'must not be empty',
    );
  }
  if (costs.isEmpty && !isMaxLevel) {
    throw ArgumentError.value(
      costs,
      'costs',
      'must not be empty unless max level',
    );
  }
  for (final stat in statChanges) {
    if (stat.label.trim().isEmpty ||
        stat.currentValue.trim().isEmpty ||
        stat.nextValue.trim().isEmpty) {
      throw ArgumentError.value(
        stat,
        'statChanges',
        'labels and values must not be empty',
      );
    }
  }
  for (final cost in costs) {
    if (cost.label.trim().isEmpty ||
        cost.currentAmount < 0 ||
        cost.requiredAmount < 0) {
      throw ArgumentError.value(
        cost,
        'costs',
        'label must be non-empty and amounts non-negative',
      );
    }
  }
}