From 98c063ed2f174412cd11fbf5c15b5088839d6b99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=B8=D0=BD=D0=B0=20=D0=A7=D1=83=D0=B1?= =?UTF-8?q?=D1=8B=D0=BA=D0=B8=D0=BD=D0=B0?= Date: Thu, 17 Oct 2024 12:19:06 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BA=D0=B0=D0=BA=D0=B8=D0=B5=20=D1=82=D0=BE?= =?UTF-8?q?=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/components/extensions/context_x.dart | 2 +- lib/components/locale/l10n/app_locale.dart | 25 ++++---- lib/data/dtos/characters_dto.g.dart | 19 ++---- lib/data/dtos/pokemon_dto.g.dart | 12 ++-- lib/data/mappers/characters_mapper.dart | 3 +- lib/presentation/home_page/bloc/state.g.dart | 3 +- lib/presentation/home_page/card.dart | 3 +- lib/presentation/home_page/home_page.dart | 60 +++++++++---------- lib/presentation/like_bloc/like_bloc.dart | 2 +- lib/presentation/like_bloc/like_event.dart | 2 +- lib/presentation/like_bloc/like_state.dart | 2 +- lib/presentation/locale_bloc/locale_bloc.dart | 2 +- .../locale_bloc/locale_events.dart | 2 +- .../locale_bloc/locale_state.dart | 2 +- .../locale_bloc/locale_state.g.dart | 12 ++-- pubspec.yaml | 4 +- 16 files changed, 68 insertions(+), 87 deletions(-) diff --git a/lib/components/extensions/context_x.dart b/lib/components/extensions/context_x.dart index a611371..8e4a7af 100644 --- a/lib/components/extensions/context_x.dart +++ b/lib/components/extensions/context_x.dart @@ -3,4 +3,4 @@ import '../locale/l10n/app_locale.dart'; extension LocalContextX on BuildContext { AppLocale get locale => AppLocale.of(this)!; -} \ No newline at end of file +} diff --git a/lib/components/locale/l10n/app_locale.dart b/lib/components/locale/l10n/app_locale.dart index 0922eb1..c819af2 100644 --- a/lib/components/locale/l10n/app_locale.dart +++ b/lib/components/locale/l10n/app_locale.dart @@ -82,7 +82,8 @@ abstract class AppLocale { /// Additional delegates can be added by appending to this list in /// MaterialApp. This list does not have to be used at all if a custom list /// of delegates is preferred or required. - static const List> localizationsDelegates = >[ + static const List> localizationsDelegates = + >[ delegate, GlobalMaterialLocalizations.delegate, GlobalCupertinoLocalizations.delegate, @@ -90,10 +91,7 @@ abstract class AppLocale { ]; /// A list of this localizations delegate's supported locales. - static const List supportedLocales = [ - Locale('en'), - Locale('ru') - ]; + static const List supportedLocales = [Locale('en'), Locale('ru')]; /// No description provided for @search. /// @@ -136,18 +134,17 @@ class _AppLocaleDelegate extends LocalizationsDelegate { } AppLocale lookupAppLocale(Locale locale) { - - // Lookup logic when only language code is specified. switch (locale.languageCode) { - case 'en': return AppLocaleEn(); - case 'ru': return AppLocaleRu(); + case 'en': + return AppLocaleEn(); + case 'ru': + return AppLocaleRu(); } throw FlutterError( - 'AppLocale.delegate failed to load unsupported locale "$locale". This is likely ' - 'an issue with the localizations generation tool. Please file an issue ' - 'on GitHub with a reproducible sample app and the gen-l10n configuration ' - 'that was used.' - ); + 'AppLocale.delegate failed to load unsupported locale "$locale". This is likely ' + 'an issue with the localizations generation tool. Please file an issue ' + 'on GitHub with a reproducible sample app and the gen-l10n configuration ' + 'that was used.'); } diff --git a/lib/data/dtos/characters_dto.g.dart b/lib/data/dtos/characters_dto.g.dart index c4e1b40..6066b05 100644 --- a/lib/data/dtos/characters_dto.g.dart +++ b/lib/data/dtos/characters_dto.g.dart @@ -6,28 +6,22 @@ part of 'characters_dto.dart'; // JsonSerializableGenerator // ************************************************************************** -CharactersDto _$CharactersDtoFromJson(Map json) => - CharactersDto( +CharactersDto _$CharactersDtoFromJson(Map json) => CharactersDto( data: (json['data'] as List?) ?.map((e) => CharacterDataDto.fromJson(e as Map)) .toList(), - meta: json['meta'] == null - ? null - : MetaDto.fromJson(json['meta'] as Map), + meta: json['meta'] == null ? null : MetaDto.fromJson(json['meta'] as Map), ); -CharacterDataDto _$CharacterDataDtoFromJson(Map json) => - CharacterDataDto( +CharacterDataDto _$CharacterDataDtoFromJson(Map json) => CharacterDataDto( id: json['id'] as String?, type: json['type'] as String?, attributes: json['attributes'] == null ? null - : CharacterAttributesDataDto.fromJson( - json['attributes'] as Map), + : CharacterAttributesDataDto.fromJson(json['attributes'] as Map), ); -CharacterAttributesDataDto _$CharacterAttributesDataDtoFromJson( - Map json) => +CharacterAttributesDataDto _$CharacterAttributesDataDtoFromJson(Map json) => CharacterAttributesDataDto( name: json['name'] as String?, born: json['born'] as String?, @@ -41,8 +35,7 @@ MetaDto _$MetaDtoFromJson(Map json) => MetaDto( : PaginationDto.fromJson(json['pagination'] as Map), ); -PaginationDto _$PaginationDtoFromJson(Map json) => - PaginationDto( +PaginationDto _$PaginationDtoFromJson(Map json) => PaginationDto( current: (json['current'] as num?)?.toInt(), next: (json['next'] as num?)?.toInt(), last: (json['last'] as num?)?.toInt(), diff --git a/lib/data/dtos/pokemon_dto.g.dart b/lib/data/dtos/pokemon_dto.g.dart index 849e083..8095bc9 100644 --- a/lib/data/dtos/pokemon_dto.g.dart +++ b/lib/data/dtos/pokemon_dto.g.dart @@ -12,24 +12,20 @@ PokemonDto _$PokemonDtoFromJson(Map json) => PokemonDto( types: (json['types'] as List) .map((e) => PokemonTypeDto.fromJson(e as Map)) .toList(), - sprites: - PokemonSpritesDto.fromJson(json['sprites'] as Map), + sprites: PokemonSpritesDto.fromJson(json['sprites'] as Map), ); -PokemonTypeDto _$PokemonTypeDtoFromJson(Map json) => - PokemonTypeDto( +PokemonTypeDto _$PokemonTypeDtoFromJson(Map json) => PokemonTypeDto( slot: (json['slot'] as num).toInt(), type: PokemonTypeDetailDto.fromJson(json['type'] as Map), ); -PokemonTypeDetailDto _$PokemonTypeDetailDtoFromJson( - Map json) => +PokemonTypeDetailDto _$PokemonTypeDetailDtoFromJson(Map json) => PokemonTypeDetailDto( name: json['name'] as String, url: json['url'] as String, ); -PokemonSpritesDto _$PokemonSpritesDtoFromJson(Map json) => - PokemonSpritesDto( +PokemonSpritesDto _$PokemonSpritesDtoFromJson(Map json) => PokemonSpritesDto( front_default: json['front_default'] as String, ); diff --git a/lib/data/mappers/characters_mapper.dart b/lib/data/mappers/characters_mapper.dart index ac74120..4f890d4 100644 --- a/lib/data/mappers/characters_mapper.dart +++ b/lib/data/mappers/characters_mapper.dart @@ -17,8 +17,7 @@ extension CharacterDataDtoToModel on CharacterDataDto { CardData toDomain() => CardData( attributes?.name ?? 'UNKNOWN', imageUrl: attributes?.image ?? _imagePlaceholder, - descriptionText: - _makeDescriptionText(attributes?.born, attributes?.died), + descriptionText: _makeDescriptionText(attributes?.born, attributes?.died), id: id, ); diff --git a/lib/presentation/home_page/bloc/state.g.dart b/lib/presentation/home_page/bloc/state.g.dart index 114ac25..258a914 100644 --- a/lib/presentation/home_page/bloc/state.g.dart +++ b/lib/presentation/home_page/bloc/state.g.dart @@ -72,8 +72,7 @@ class _$HomeStateCWProxyImpl implements _$HomeStateCWProxy { // ignore: cast_nullable_to_non_nullable : isLoading as bool, isPaginationLoading: - isPaginationLoading == const $CopyWithPlaceholder() || - isPaginationLoading == null + isPaginationLoading == const $CopyWithPlaceholder() || isPaginationLoading == null ? _value.isPaginationLoading // ignore: cast_nullable_to_non_nullable : isPaginationLoading as bool, diff --git a/lib/presentation/home_page/card.dart b/lib/presentation/home_page/card.dart index f8e3fd6..5f80dae 100644 --- a/lib/presentation/home_page/card.dart +++ b/lib/presentation/home_page/card.dart @@ -105,8 +105,7 @@ class _Card extends StatelessWidget { Align( alignment: Alignment.bottomRight, child: Padding( - padding: - const EdgeInsets.only(left: 8, right: 16, bottom: 16), + padding: const EdgeInsets.only(left: 8, right: 16, bottom: 16), child: GestureDetector( onTap: () => onLike?.call(id, text, isLiked), child: AnimatedSwitcher( diff --git a/lib/presentation/home_page/home_page.dart b/lib/presentation/home_page/home_page.dart index e4beb06..bfa8895 100644 --- a/lib/presentation/home_page/home_page.dart +++ b/lib/presentation/home_page/home_page.dart @@ -98,7 +98,7 @@ class BodyState extends State { placeholder: context.locale.search, onChanged: (search) { Debounce.run( - () => context.read().add(HomeLoadDataEvent(search: search))); + () => context.read().add(HomeLoadDataEvent(search: search))); }, ), ), @@ -124,36 +124,36 @@ class BodyState extends State { BlocBuilder( builder: (context, state) => state.error != null ? Text( - state.error ?? '', - style: Theme.of(context).textTheme.headlineSmall?.copyWith(color: Colors.red), - ) + state.error ?? '', + style: Theme.of(context).textTheme.headlineSmall?.copyWith(color: Colors.red), + ) : state.isLoading - ? const CircularProgressIndicator() - : BlocBuilder( - builder: (context, likeState) { - return Expanded( - child: RefreshIndicator( - onRefresh: _onRefresh, - child: ListView.builder( - controller: scrollController, - padding: EdgeInsets.zero, - itemCount: state.data?.data?.length ?? 0, - itemBuilder: (context, index) { - final data = state.data?.data?[index]; - return data != null - ? _Card.fromData( - data, - onLike: _onLike, - isLiked: likeState.likedIds?.contains(data.id) == true, - onTap: () => _navToDetails(context, data), - ) - : const SizedBox.shrink(); - }, - ), - ), - ); - }, - ), + ? const CircularProgressIndicator() + : BlocBuilder( + builder: (context, likeState) { + return Expanded( + child: RefreshIndicator( + onRefresh: _onRefresh, + child: ListView.builder( + controller: scrollController, + padding: EdgeInsets.zero, + itemCount: state.data?.data?.length ?? 0, + itemBuilder: (context, index) { + final data = state.data?.data?[index]; + return data != null + ? _Card.fromData( + data, + onLike: _onLike, + isLiked: likeState.likedIds?.contains(data.id) == true, + onTap: () => _navToDetails(context, data), + ) + : const SizedBox.shrink(); + }, + ), + ), + ); + }, + ), ), BlocBuilder( builder: (context, state) => state.isPaginationLoading diff --git a/lib/presentation/like_bloc/like_bloc.dart b/lib/presentation/like_bloc/like_bloc.dart index 5ba512c..2b57711 100644 --- a/lib/presentation/like_bloc/like_bloc.dart +++ b/lib/presentation/like_bloc/like_bloc.dart @@ -33,4 +33,4 @@ class LikeBloc extends Bloc { emit(state.copyWith(likedIds: updatedList)); } -} \ No newline at end of file +} diff --git a/lib/presentation/like_bloc/like_event.dart b/lib/presentation/like_bloc/like_event.dart index 43032db..d0326d8 100644 --- a/lib/presentation/like_bloc/like_event.dart +++ b/lib/presentation/like_bloc/like_event.dart @@ -10,4 +10,4 @@ class ChangeLikeEvent extends LikeEvent { final String id; const ChangeLikeEvent(this.id); -} \ No newline at end of file +} diff --git a/lib/presentation/like_bloc/like_state.dart b/lib/presentation/like_bloc/like_state.dart index 0099c7c..5f0959f 100644 --- a/lib/presentation/like_bloc/like_state.dart +++ b/lib/presentation/like_bloc/like_state.dart @@ -11,4 +11,4 @@ class LikeState extends Equatable { @override List get props => [likedIds]; -} \ No newline at end of file +} diff --git a/lib/presentation/locale_bloc/locale_bloc.dart b/lib/presentation/locale_bloc/locale_bloc.dart index cb29a7f..8fc3b69 100644 --- a/lib/presentation/locale_bloc/locale_bloc.dart +++ b/lib/presentation/locale_bloc/locale_bloc.dart @@ -14,4 +14,4 @@ class LocaleBloc extends Bloc { .firstWhere((e) => e.languageCode != state.currentLocale.languageCode); emit(state.copyWith(currentLocale: toChange)); } -} \ No newline at end of file +} diff --git a/lib/presentation/locale_bloc/locale_events.dart b/lib/presentation/locale_bloc/locale_events.dart index f345ef9..c08cd1b 100644 --- a/lib/presentation/locale_bloc/locale_events.dart +++ b/lib/presentation/locale_bloc/locale_events.dart @@ -4,4 +4,4 @@ abstract class LocaleEvent { class ChangeLocaleEvent extends LocaleEvent { const ChangeLocaleEvent(); -} \ No newline at end of file +} diff --git a/lib/presentation/locale_bloc/locale_state.dart b/lib/presentation/locale_bloc/locale_state.dart index 8539fbf..b9221ca 100644 --- a/lib/presentation/locale_bloc/locale_state.dart +++ b/lib/presentation/locale_bloc/locale_state.dart @@ -12,4 +12,4 @@ class LocaleState extends Equatable { @override List get props => [currentLocale]; -} \ No newline at end of file +} diff --git a/lib/presentation/locale_bloc/locale_state.g.dart b/lib/presentation/locale_bloc/locale_state.g.dart index e374db6..23ee063 100644 --- a/lib/presentation/locale_bloc/locale_state.g.dart +++ b/lib/presentation/locale_bloc/locale_state.g.dart @@ -27,8 +27,7 @@ class _$LocaleStateCWProxyImpl implements _$LocaleStateCWProxy { final LocaleState _value; @override - LocaleState currentLocale(Locale currentLocale) => - this(currentLocale: currentLocale); + LocaleState currentLocale(Locale currentLocale) => this(currentLocale: currentLocale); @override @@ -42,11 +41,10 @@ class _$LocaleStateCWProxyImpl implements _$LocaleStateCWProxy { Object? currentLocale = const $CopyWithPlaceholder(), }) { return LocaleState( - currentLocale: - currentLocale == const $CopyWithPlaceholder() || currentLocale == null - ? _value.currentLocale - // ignore: cast_nullable_to_non_nullable - : currentLocale as Locale, + currentLocale: currentLocale == const $CopyWithPlaceholder() || currentLocale == null + ? _value.currentLocale + // ignore: cast_nullable_to_non_nullable + : currentLocale as Locale, ); } } diff --git a/pubspec.yaml b/pubspec.yaml index b011b02..bb06205 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -22,7 +22,7 @@ dependencies: copy_with_extension_gen: ^5.0.4 flutter_localizations: - sdk: flutter + sdk: flutter intl: ^0.19.0 shared_preferences: 2.2.3 @@ -49,4 +49,4 @@ flutter: uses-material-design: true assets: - - assets/svg/ + - assets/svg/ \ No newline at end of file