Skip to content

Commit

Permalink
fix: about page and pokemon fitt title in details
Browse files Browse the repository at this point in the history
  • Loading branch information
brunogabriel committed Oct 31, 2024
1 parent b18bef7 commit 5026747
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 55 deletions.
15 changes: 9 additions & 6 deletions pokedex/lib/design/components/pokemon_information.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,15 @@ class PokemonInformation extends StatelessWidget {
),
),
const SizedBox(height: PokedexSpacing.kXS),
Text(
pokemon.name.capitalize(),
overflow: TextOverflow.ellipsis,
style: textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.bold,
color: Colors.white,
FittedBox(
fit: BoxFit.fitWidth,
child: Text(
pokemon.name.capitalize(),
overflow: TextOverflow.ellipsis,
style: textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.bold,
color: Colors.white,
),
),
),
],
Expand Down
8 changes: 7 additions & 1 deletion pokedex/lib/feature/about/domain/about_use_case.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@ class AboutUseCaseImpl implements AboutUseCase {
final Pokedex _client;
@override
Future<AboutEntity> getAbout(Pokemon pokemon) async {
final species = await _client.pokemonSpecies.get(id: pokemon.id);
final types = await Future.wait(pokemon.types
.map((e) => e.type.url)
.map((e) => _client.types.getByUrl(e)));

PokemonSpecies? species;
try {
species = await _client.pokemonSpecies.get(id: pokemon.id);
} catch (_) {
species = null;
}

final weaknesses = types.damageFrom.entries
.where((element) => element.value > 1)
.map((e) => e.key)
Expand Down
2 changes: 1 addition & 1 deletion pokedex/lib/feature/about/domain/entity/about_entity.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ class AboutEntity {
});

final Pokemon pokemon;
final PokemonSpecies pokemonSpecies;
final PokemonSpecies? pokemonSpecies;
final List<String> weaknesses;
}
101 changes: 54 additions & 47 deletions pokedex/lib/feature/about/presentation/widgets/about_success.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class AboutSuccess extends StatelessWidget {
final items = <Widget>[
// Title
Text(
species.flavorTextEntries
species?.flavorTextEntries
.firstWhereOrNull((element) => element.language.name == 'en')
?.flavorText
.replaceScapeChars() ??
Expand All @@ -45,12 +45,14 @@ class AboutSuccess extends StatelessWidget {
),
// Pokedex Data
Text(AboutStrings.pokedexData, style: sectionTheme),
AboutTile(
title: AboutStrings.species,
content: species.genera
.firstWhereOrNull((element) => element.language.name == 'en')
?.genus,
),
if (species != null) ...{
AboutTile(
title: AboutStrings.species,
content: species.genera
.firstWhereOrNull((element) => element.language.name == 'en')
?.genus,
),
},
AboutTile(
title: AboutStrings.height,
content: '${pokemon.height.meter.toStringAsFixed(1)}m',
Expand Down Expand Up @@ -80,24 +82,28 @@ class AboutSuccess extends StatelessWidget {
),
// Trainning
Text(AboutStrings.trainning, style: sectionTheme),
AboutTile(
title: AboutStrings.catchRate,
content: species.captureRate.toString()),
if (species != null) ...{
AboutTile(
title: AboutStrings.catchRate,
content: species.captureRate.toString()),
},
AboutTile(
title: AboutStrings.baseExp,
content: pokemon.baseExperience != null
? pokemon.baseExperience.toString()
: AboutStrings.unknown,
),
AboutTile(
title: AboutStrings.growthRate,
content: species.growthRate.name.capitalizeKebabCase(),
),
if (species != null) ...{
AboutTile(
title: AboutStrings.growthRate,
content: species.growthRate.name.capitalizeKebabCase(),
),
},

// Trainning
Text(AboutStrings.breeding, style: sectionTheme),

if (species.genderRate == -1) ...{
if (species == null || species.genderRate == -1) ...{
const AboutTile(
title: AboutStrings.gender,
content: AboutStrings.unknown,
Expand Down Expand Up @@ -132,40 +138,41 @@ class AboutSuccess extends StatelessWidget {
),
},

AboutTile(
title: AboutStrings.eggGroups,
content: species.eggGroups
.map((e) => e.name.capitalize().capitalizeKebabCase())
.join(', '),
),

AboutTile.custom(
title: AboutStrings.eggCycles,
custom: RichText(
text: TextSpan(
children: [
if (species.hatchCounter != null) ...{
TextSpan(
text: '${species.hatchCounter ?? 0} ',
style: textTheme.bodyLarge
?.copyWith(color: PokedexThemeData.textGrey),
),
TextSpan(
text:
'(${(species.hatchCounter ?? 0) * 244} - ${(species.hatchCounter ?? 0) * 257} steps)',
style: textTheme.bodySmall
?.copyWith(color: PokedexThemeData.textGrey),
)
} else ...{
TextSpan(
text: '-',
if (species != null) ...{
AboutTile(
title: AboutStrings.eggGroups,
content: species.eggGroups
.map((e) => e.name.capitalize().capitalizeKebabCase())
.join(', '),
),
AboutTile.custom(
title: AboutStrings.eggCycles,
custom: RichText(
text: TextSpan(
children: [
if (species.hatchCounter != null) ...{
TextSpan(
text: '${species.hatchCounter ?? 0} ',
style: textTheme.bodyLarge
?.copyWith(color: PokedexThemeData.textGrey))
}
],
?.copyWith(color: PokedexThemeData.textGrey),
),
TextSpan(
text:
'(${(species.hatchCounter ?? 0) * 244} - ${(species.hatchCounter ?? 0) * 257} steps)',
style: textTheme.bodySmall
?.copyWith(color: PokedexThemeData.textGrey),
)
} else ...{
TextSpan(
text: '-',
style: textTheme.bodyLarge
?.copyWith(color: PokedexThemeData.textGrey))
}
],
),
),
),
)
)
}
];

return ListView.separated(
Expand Down

0 comments on commit 5026747

Please sign in to comment.