Skip to content

Commit

Permalink
[Infrastructure] Migrate to null safety
Browse files Browse the repository at this point in the history
  • Loading branch information
Wolfteam committed Jun 19, 2021
1 parent c76c2c2 commit 7a06041
Show file tree
Hide file tree
Showing 13 changed files with 178 additions and 170 deletions.
2 changes: 1 addition & 1 deletion lib/application/notification/notification_bloc.dart
Expand Up @@ -591,7 +591,7 @@ class NotificationBloc extends Bloc<NotificationEvent, NotificationState> {
final selectedItemKey = _getSelectedItemKey();
if (s.key != null) {
final updated = await _dataService.updateCustomNotification(
s.key,
s.key!,
selectedItemKey,
s.title,
s.body,
Expand Down
2 changes: 1 addition & 1 deletion lib/domain/services/data_service.dart
Expand Up @@ -265,7 +265,7 @@ abstract class DataService {
});

Future<NotificationItem> updateCustomNotification(
int? key,
int key,
String itemKey,
String title,
String body,
Expand Down
16 changes: 9 additions & 7 deletions lib/infrastructure/calculator_service.dart
Expand Up @@ -65,6 +65,8 @@ class CalculatorServiceImpl implements CalculatorService {
case MaterialType.expCharacter:
key = AscensionMaterialSummaryType.exp;
break;
case MaterialType.all:
throw Exception('Material type ${material.type} should not be here');
}
newValue = MaterialSummary.others(
key: material.key,
Expand All @@ -75,12 +77,12 @@ class CalculatorServiceImpl implements CalculatorService {
}

if (summary.containsKey(key)) {
summary[key].add(newValue);
summary[key]!.add(newValue);
} else {
summary.putIfAbsent(key, () => [newValue]);
}

summary[key].sort((x, y) => x.key.compareTo(y.key));
summary[key]!.sort((x, y) => x.key.compareTo(y.key));
}

return summary.entries.map((entry) => AscensionMaterialsSummary(type: entry.key, materials: entry.value)).toList();
Expand Down Expand Up @@ -115,12 +117,12 @@ class CalculatorServiceImpl implements CalculatorService {

skillMaterials.addAll(materials);
}
} else if (char.multiTalentAscensionMaterials != null && char.multiTalentAscensionMaterials.isNotEmpty) {
} else if (char.multiTalentAscensionMaterials != null && char.multiTalentAscensionMaterials!.isNotEmpty) {
//The traveler has different materials depending on the skill, that's why we need to retrieve the right amount for the provided skill
//Also, we are assuming that the skill's order are fixed
var talentNumber = 1;
for (final skill in skills) {
final materials = char.multiTalentAscensionMaterials
final materials = char.multiTalentAscensionMaterials!
.where((mt) => mt.number == talentNumber)
.expand((mt) => mt.materials)
.where((m) => m.level > skill.currentLevel && m.level <= skill.desiredLevel)
Expand Down Expand Up @@ -340,7 +342,7 @@ class CalculatorServiceImpl implements CalculatorService {
final materials = <ItemAscensionMaterialModel>[];
//Here we order the exp materials in a way that the one that gives more exp is first and so on
final expMaterials = _genshinService.getMaterials(forCharacters ? MaterialType.expCharacter : MaterialType.expWeapon)
..sort((x, y) => (y.experienceAttributes.experience - x.experienceAttributes.experience).round());
..sort((x, y) => (y.experienceAttributes!.experience - x.experienceAttributes!.experience).round());
var requiredExp = getItemTotalExp(currentLevel, desiredLevel, rarity, forCharacters);
final moraMaterial = _genshinService.getMaterials(MaterialType.currency).first;

Expand All @@ -349,15 +351,15 @@ class CalculatorServiceImpl implements CalculatorService {
break;
}

final matExp = material.experienceAttributes.experience;
final matExp = material.experienceAttributes!.experience;
final quantity = (requiredExp / matExp).floor();
if (quantity == 0) {
continue;
}
materials.add(ItemAscensionMaterialModel(quantity: quantity, image: material.image, materialType: material.type));
requiredExp -= quantity * matExp;

final requiredMora = quantity * material.experienceAttributes.pricePerUsage;
final requiredMora = quantity * material.experienceAttributes!.pricePerUsage;
materials.add(ItemAscensionMaterialModel(quantity: requiredMora.round(), image: moraMaterial.image, materialType: moraMaterial.type));
}

Expand Down

0 comments on commit 7a06041

Please sign in to comment.