UpgradePreviewPanel constructor
UpgradePreviewPanel({
- Key? key,
- required String title,
- required int currentLevel,
- required int nextLevel,
- required List<
UpgradeStatChange> statChanges, - required List<
UpgradeCost> costs, - required VoidCallback onUpgrade,
- bool isMaxLevel = false,
- bool isUpgrading = false,
- String upgradeLabel = 'Upgrade',
- String maxLevelLabel = 'MAX LEVEL',
- String? subtitle,
- 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',
);
}
}
}