Skip to content

Commit

Permalink
[Domain] 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 bba1542 commit 292ea1b
Show file tree
Hide file tree
Showing 75 changed files with 617 additions and 688 deletions.
2 changes: 1 addition & 1 deletion lib/domain/assets.dart
Expand Up @@ -62,7 +62,7 @@ class Assets {

static String getCharacterFullPath(String name) => '$characterFullBasePath/$name';

static String getSkillPath(String name) {
static String getSkillPath(String? name) {
if (name.isNullEmptyOrWhitespace) {
return '$othersBasePath/$noImageAvailableName';
}
Expand Down
4 changes: 2 additions & 2 deletions lib/domain/extensions/duration_extensions.dart
@@ -1,9 +1,9 @@
import 'package:genshindb/domain/extensions/string_extensions.dart';

extension DurationExtensions on Duration {
String formatDuration({String negativeText}) {
String formatDuration({String? negativeText}) {
if (isNegative) {
return negativeText.isNotNullEmptyOrWhitespace ? negativeText : '∞';
return negativeText.isNotNullEmptyOrWhitespace ? negativeText! : '∞';
}
String twoDigits(num n) => n.toString().padLeft(2, '0');
final twoDigitHour = twoDigits(inHours);
Expand Down
6 changes: 3 additions & 3 deletions lib/domain/extensions/string_extensions.dart
@@ -1,6 +1,6 @@
extension StringExtensions on String {
bool get isNullEmptyOrWhitespace => this == null || isEmpty;
extension StringExtensions on String? {
bool get isNullEmptyOrWhitespace => this == null || this!.isEmpty;
bool get isNotNullEmptyOrWhitespace => !isNullEmptyOrWhitespace;

bool isValidLength({int minLength = 0, int maxLength = 255}) => isNotNullEmptyOrWhitespace || length > maxLength || length < minLength;
bool isValidLength({int minLength = 0, int maxLength = 255}) => isNotNullEmptyOrWhitespace || this!.length > maxLength || this!.length < minLength;
}
16 changes: 7 additions & 9 deletions lib/domain/models/artifacts/artifact_card_model.dart
@@ -1,5 +1,3 @@
import 'package:flutter/widgets.dart';

class ArtifactCardModel {
final String key;
final String name;
Expand All @@ -8,11 +6,11 @@ class ArtifactCardModel {
final List<ArtifactCardBonusModel> bonus;

const ArtifactCardModel({
@required this.key,
@required this.name,
@required this.image,
@required this.rarity,
@required this.bonus,
required this.key,
required this.name,
required this.image,
required this.rarity,
required this.bonus,
});
}

Expand All @@ -21,7 +19,7 @@ class ArtifactCardBonusModel {
final String bonus;

const ArtifactCardBonusModel({
@required this.pieces,
@required this.bonus,
required this.pieces,
required this.bonus,
});
}
@@ -1,47 +1,45 @@
import 'package:flutter/foundation.dart';

import '../../enums/ascension_material_summary_type.dart';
import '../../enums/material_type.dart';

class AscensionMaterialsSummary {
final AscensionMaterialSummaryType type;
final AscensionMaterialSummaryType? type;
final List<MaterialSummary> materials;

const AscensionMaterialsSummary({
@required this.type,
@required this.materials,
required this.type,
required this.materials,
});
}

class MaterialSummary {
final String key;
final MaterialType materialType;
final String fullImagePath;
final String? fullImagePath;
final int quantity;
final bool isFromBoss;
final List<int> days;

const MaterialSummary.others({
@required this.key,
@required this.materialType,
@required this.fullImagePath,
@required this.quantity,
}) : isFromBoss = false,
required this.key,
required this.materialType,
required this.fullImagePath,
required this.quantity,
}) : isFromBoss = false,
days = const [];

const MaterialSummary.fromBoss({
@required this.key,
@required this.materialType,
@required this.fullImagePath,
@required this.quantity,
}) : isFromBoss = true,
required this.key,
required this.materialType,
required this.fullImagePath,
required this.quantity,
}) : isFromBoss = true,
days = const [];

const MaterialSummary.fromDays({
@required this.key,
@required this.materialType,
@required this.fullImagePath,
@required this.quantity,
@required this.days,
required this.key,
required this.materialType,
required this.fullImagePath,
required this.quantity,
required this.days,
}) : isFromBoss = false;
}
@@ -1,4 +1,3 @@
import 'package:flutter/foundation.dart';
import 'package:genshindb/domain/models/models.dart';

class CalculatorSessionModel {
Expand All @@ -8,9 +7,9 @@ class CalculatorSessionModel {
final List<ItemAscensionMaterials> items;

CalculatorSessionModel({
@required this.key,
@required this.name,
@required this.position,
@required this.items,
required this.key,
required this.name,
required this.position,
required this.items,
});
}
20 changes: 10 additions & 10 deletions lib/domain/models/calculator_asc_materials/character_skill.dart
Expand Up @@ -4,16 +4,16 @@ import 'package:freezed_annotation/freezed_annotation.dart';
part 'character_skill.freezed.dart';

@freezed
abstract class CharacterSkill with _$CharacterSkill {
class CharacterSkill with _$CharacterSkill {
const factory CharacterSkill.skill({
@required String key,
@required int position,
@required String name,
@required int currentLevel,
@required int desiredLevel,
@required bool isCurrentIncEnabled,
@required bool isCurrentDecEnabled,
@required bool isDesiredIncEnabled,
@required bool isDesiredDecEnabled,
required String key,
required int position,
required String name,
required int currentLevel,
required int desiredLevel,
required bool isCurrentIncEnabled,
required bool isCurrentDecEnabled,
required bool isDesiredIncEnabled,
required bool isDesiredDecEnabled,
}) = _CharacterSkill;
}
Expand Up @@ -6,37 +6,37 @@ import '../models.dart';
part 'item_ascension_materials.freezed.dart';

@freezed
abstract class ItemAscensionMaterials with _$ItemAscensionMaterials {
class ItemAscensionMaterials with _$ItemAscensionMaterials {
const factory ItemAscensionMaterials.forCharacters({
@required String key,
@required String name,
@required int position,
@required String image,
@required int rarity,
@required List<ItemAscensionMaterialModel> materials,
@required int currentLevel,
@required int desiredLevel,
@required int currentAscensionLevel,
@required int desiredAscensionLevel,
@required List<CharacterSkill> skills,
@required bool useMaterialsFromInventory,
required String key,
required String name,
required int position,
required String image,
required int rarity,
required List<ItemAscensionMaterialModel> materials,
required int currentLevel,
required int desiredLevel,
required int currentAscensionLevel,
required int desiredAscensionLevel,
required List<CharacterSkill> skills,
required bool useMaterialsFromInventory,
@Default(true) bool isCharacter,
@Default(false) bool isWeapon,
@Default(true) bool isActive,
}) = _ForCharacter;

const factory ItemAscensionMaterials.forWeapons({
@required String key,
@required String name,
@required String image,
@required int position,
@required int rarity,
@required List<ItemAscensionMaterialModel> materials,
@required int currentLevel,
@required int desiredLevel,
@required int currentAscensionLevel,
@required int desiredAscensionLevel,
@required bool useMaterialsFromInventory,
required String key,
required String name,
required String image,
required int position,
required int rarity,
required List<ItemAscensionMaterialModel> materials,
required int currentLevel,
required int desiredLevel,
required int currentAscensionLevel,
required int desiredAscensionLevel,
required bool useMaterialsFromInventory,
//This are here just for convenience
@Default([]) List<CharacterSkill> skills,
@Default(false) bool isCharacter,
Expand Down
8 changes: 3 additions & 5 deletions lib/domain/models/characters/character_ascension_model.dart
@@ -1,5 +1,3 @@
import 'package:flutter/widgets.dart';

import '../items/item_ascension_material_model.dart';

class CharacterAscensionModel {
Expand All @@ -8,8 +6,8 @@ class CharacterAscensionModel {
final List<ItemAscensionMaterialModel> materials;

CharacterAscensionModel({
@required this.rank,
@required this.level,
@required this.materials,
required this.rank,
required this.level,
required this.materials,
});
}
29 changes: 14 additions & 15 deletions lib/domain/models/characters/character_build_card_model.dart
@@ -1,4 +1,3 @@
import 'package:flutter/foundation.dart';
import 'package:genshindb/domain/enums/enums.dart';

import '../models.dart';
Expand All @@ -10,40 +9,40 @@ class CharacterBuildCardModel {
final List<StatType> subStatsToFocus;

CharacterBuildCardModel({
@required this.isForSupport,
@required this.weapons,
@required this.artifacts,
@required this.subStatsToFocus,
required this.isForSupport,
required this.weapons,
required this.artifacts,
required this.subStatsToFocus,
});
}

class CharacterBuildArtifactModel {
final ArtifactCardModel one;
final ArtifactCardModel? one;
final List<CharacterBuildMultipleArtifactModel> multiples;
final List<StatType> stats;

const CharacterBuildArtifactModel({
@required this.one,
@required this.multiples,
@required this.stats,
required this.one,
required this.multiples,
required this.stats,
});

const CharacterBuildArtifactModel.one({
@required this.one,
@required this.stats,
required this.one,
required this.stats,
}) : multiples = const [];

const CharacterBuildArtifactModel.multiples({
@required this.multiples,
@required this.stats,
required this.multiples,
required this.stats,
}) : one = null;
}

class CharacterBuildMultipleArtifactModel {
final int quantity;
final ArtifactCardModel artifact;
CharacterBuildMultipleArtifactModel({
@required this.quantity,
@required this.artifact,
required this.quantity,
required this.artifact,
});
}
18 changes: 8 additions & 10 deletions lib/domain/models/characters/character_card_model.dart
@@ -1,5 +1,3 @@
import 'package:flutter/widgets.dart';

import '../../enums/enums.dart';

class CharacterCardModel {
Expand All @@ -15,14 +13,14 @@ class CharacterCardModel {
final CharacterRoleType roleType;

const CharacterCardModel({
@required this.key,
@required this.logoName,
@required this.name,
@required this.stars,
@required this.weaponType,
@required this.elementType,
@required this.materials,
@required this.roleType,
required this.key,
required this.logoName,
required this.name,
required this.stars,
required this.weaponType,
required this.elementType,
required this.materials,
required this.roleType,
this.isNew = false,
this.isComingSoon = false,
});
Expand Down
12 changes: 5 additions & 7 deletions lib/domain/models/characters/character_constellation_model.dart
@@ -1,18 +1,16 @@
import 'package:flutter/widgets.dart';

class CharacterConstellationModel {
final int number;
final String image;
final String title;
final String description;
final String secondDescription;
final String? secondDescription;
final List<String> descriptions;

const CharacterConstellationModel({
@required this.number,
@required this.image,
@required this.title,
@required this.description,
required this.number,
required this.image,
required this.title,
required this.description,
this.secondDescription,
this.descriptions = const [],
});
Expand Down
10 changes: 4 additions & 6 deletions lib/domain/models/characters/character_passive_talent_model.dart
@@ -1,5 +1,3 @@
import 'package:flutter/widgets.dart';

class CharacterPassiveTalentModel {
final int unlockedAt;
final String image;
Expand All @@ -8,10 +6,10 @@ class CharacterPassiveTalentModel {
final List<String> descriptions;

CharacterPassiveTalentModel({
@required this.unlockedAt,
@required this.image,
@required this.title,
@required this.description,
required this.unlockedAt,
required this.image,
required this.title,
required this.description,
this.descriptions = const [],
});
}

0 comments on commit 292ea1b

Please sign in to comment.