From 0f45968d63869650654d1a2fa4545b1952babc99 Mon Sep 17 00:00:00 2001 From: Bruno Gabriel dos Santos Date: Thu, 31 Oct 2024 12:57:13 -0300 Subject: [PATCH] fix: layout structure when title is null and status section title --- .../components/pokemon_information.dart | 2 +- pokedex/lib/design/components/stat_line.dart | 11 +++++--- .../presentation/widgets/about_success.dart | 19 ++++++++------ .../evolution/domain/evolution_use_case.dart | 25 ++++++++++++++----- 4 files changed, 39 insertions(+), 18 deletions(-) diff --git a/pokedex/lib/design/components/pokemon_information.dart b/pokedex/lib/design/components/pokemon_information.dart index b0b51ce..f1fb4aa 100644 --- a/pokedex/lib/design/components/pokemon_information.dart +++ b/pokedex/lib/design/components/pokemon_information.dart @@ -36,7 +36,7 @@ class PokemonInformation extends StatelessWidget { ), const SizedBox(height: PokedexSpacing.kXS), FittedBox( - fit: BoxFit.fitWidth, + fit: BoxFit.scaleDown, child: Text( pokemon.name.capitalizeName(), overflow: TextOverflow.ellipsis, diff --git a/pokedex/lib/design/components/stat_line.dart b/pokedex/lib/design/components/stat_line.dart index f4b4eb5..01e8935 100644 --- a/pokedex/lib/design/components/stat_line.dart +++ b/pokedex/lib/design/components/stat_line.dart @@ -28,9 +28,14 @@ class StatLine extends StatelessWidget { children: [ Expanded( flex: 2, - child: Text( - title, - style: textTheme.labelMedium?.copyWith(fontWeight: FontWeight.bold), + child: FittedBox( + fit: BoxFit.scaleDown, + alignment: Alignment.topLeft, + child: Text( + title, + style: + textTheme.labelMedium?.copyWith(fontWeight: FontWeight.bold), + ), ), ), Expanded( diff --git a/pokedex/lib/feature/about/presentation/widgets/about_success.dart b/pokedex/lib/feature/about/presentation/widgets/about_success.dart index 382f926..de2a49d 100644 --- a/pokedex/lib/feature/about/presentation/widgets/about_success.dart +++ b/pokedex/lib/feature/about/presentation/widgets/about_success.dart @@ -32,17 +32,20 @@ class AboutSuccess extends StatelessWidget { color: primaryColor, fontWeight: FontWeight.bold, ); + final pokemonDescription = species?.flavorTextEntries + .firstWhereOrNull((element) => element.language.name == 'en') + ?.flavorText + .replaceScapeChars(); final items = [ // Title - Text( - species?.flavorTextEntries - .firstWhereOrNull((element) => element.language.name == 'en') - ?.flavorText - .replaceScapeChars() ?? - '', - style: textTheme.bodyLarge?.copyWith(color: PokedexThemeData.textGrey), - ), + if (pokemonDescription != null) ...{ + Text( + pokemonDescription, + style: + textTheme.bodyLarge?.copyWith(color: PokedexThemeData.textGrey), + ), + }, // Pokedex Data Text(AboutStrings.pokedexData, style: sectionTheme), if (species != null) ...{ diff --git a/pokedex/lib/feature/evolution/domain/evolution_use_case.dart b/pokedex/lib/feature/evolution/domain/evolution_use_case.dart index ae726a3..6efd427 100644 --- a/pokedex/lib/feature/evolution/domain/evolution_use_case.dart +++ b/pokedex/lib/feature/evolution/domain/evolution_use_case.dart @@ -23,14 +23,27 @@ class EvolutionUseCaseImpl implements EvolutionUseCase { @override Future getEvoluions(Pokemon pokemon) async { - final species = await _pokedex.pokemonSpecies.get(id: pokemon.id); - final evolutionChain = await _pokedex.evolutionChains - .getByUrl(species.evolutionChain?.url ?? ''); + PokemonSpecies? species; + try { + species = await _pokedex.pokemonSpecies.get(id: pokemon.id); + } catch (_) { + species = null; + } + EvolutionChain? evolutionChain; + if (species != null) { + evolutionChain = await _pokedex.evolutionChains + .getByUrl(species.evolutionChain?.url ?? ''); + } else { + evolutionChain = null; + } + return EvolutionEntity( pokemon: pokemon, - evolutions: _calculateBreadthFirstSearch(evolutionChain.chain) - .map((e) => _evolutionMapper.toEntity(e)) - .toList(), + evolutions: evolutionChain != null + ? _calculateBreadthFirstSearch(evolutionChain.chain) + .map((e) => _evolutionMapper.toEntity(e)) + .toList() + : [], ); }