какие то изменения

This commit is contained in:
Полина Чубыкина 2024-10-17 12:19:06 +04:00
parent d2b4355e37
commit 98c063ed2f
16 changed files with 68 additions and 87 deletions

View File

@ -3,4 +3,4 @@ import '../locale/l10n/app_locale.dart';
extension LocalContextX on BuildContext {
AppLocale get locale => AppLocale.of(this)!;
}
}

View File

@ -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<LocalizationsDelegate<dynamic>> localizationsDelegates = <LocalizationsDelegate<dynamic>>[
static const List<LocalizationsDelegate<dynamic>> localizationsDelegates =
<LocalizationsDelegate<dynamic>>[
delegate,
GlobalMaterialLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
@ -90,10 +91,7 @@ abstract class AppLocale {
];
/// A list of this localizations delegate's supported locales.
static const List<Locale> supportedLocales = <Locale>[
Locale('en'),
Locale('ru')
];
static const List<Locale> supportedLocales = <Locale>[Locale('en'), Locale('ru')];
/// No description provided for @search.
///
@ -136,18 +134,17 @@ class _AppLocaleDelegate extends LocalizationsDelegate<AppLocale> {
}
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.');
}

View File

@ -6,28 +6,22 @@ part of 'characters_dto.dart';
// JsonSerializableGenerator
// **************************************************************************
CharactersDto _$CharactersDtoFromJson(Map<String, dynamic> json) =>
CharactersDto(
CharactersDto _$CharactersDtoFromJson(Map<String, dynamic> json) => CharactersDto(
data: (json['data'] as List<dynamic>?)
?.map((e) => CharacterDataDto.fromJson(e as Map<String, dynamic>))
.toList(),
meta: json['meta'] == null
? null
: MetaDto.fromJson(json['meta'] as Map<String, dynamic>),
meta: json['meta'] == null ? null : MetaDto.fromJson(json['meta'] as Map<String, dynamic>),
);
CharacterDataDto _$CharacterDataDtoFromJson(Map<String, dynamic> json) =>
CharacterDataDto(
CharacterDataDto _$CharacterDataDtoFromJson(Map<String, dynamic> json) => CharacterDataDto(
id: json['id'] as String?,
type: json['type'] as String?,
attributes: json['attributes'] == null
? null
: CharacterAttributesDataDto.fromJson(
json['attributes'] as Map<String, dynamic>),
: CharacterAttributesDataDto.fromJson(json['attributes'] as Map<String, dynamic>),
);
CharacterAttributesDataDto _$CharacterAttributesDataDtoFromJson(
Map<String, dynamic> json) =>
CharacterAttributesDataDto _$CharacterAttributesDataDtoFromJson(Map<String, dynamic> json) =>
CharacterAttributesDataDto(
name: json['name'] as String?,
born: json['born'] as String?,
@ -41,8 +35,7 @@ MetaDto _$MetaDtoFromJson(Map<String, dynamic> json) => MetaDto(
: PaginationDto.fromJson(json['pagination'] as Map<String, dynamic>),
);
PaginationDto _$PaginationDtoFromJson(Map<String, dynamic> json) =>
PaginationDto(
PaginationDto _$PaginationDtoFromJson(Map<String, dynamic> json) => PaginationDto(
current: (json['current'] as num?)?.toInt(),
next: (json['next'] as num?)?.toInt(),
last: (json['last'] as num?)?.toInt(),

View File

@ -12,24 +12,20 @@ PokemonDto _$PokemonDtoFromJson(Map<String, dynamic> json) => PokemonDto(
types: (json['types'] as List<dynamic>)
.map((e) => PokemonTypeDto.fromJson(e as Map<String, dynamic>))
.toList(),
sprites:
PokemonSpritesDto.fromJson(json['sprites'] as Map<String, dynamic>),
sprites: PokemonSpritesDto.fromJson(json['sprites'] as Map<String, dynamic>),
);
PokemonTypeDto _$PokemonTypeDtoFromJson(Map<String, dynamic> json) =>
PokemonTypeDto(
PokemonTypeDto _$PokemonTypeDtoFromJson(Map<String, dynamic> json) => PokemonTypeDto(
slot: (json['slot'] as num).toInt(),
type: PokemonTypeDetailDto.fromJson(json['type'] as Map<String, dynamic>),
);
PokemonTypeDetailDto _$PokemonTypeDetailDtoFromJson(
Map<String, dynamic> json) =>
PokemonTypeDetailDto _$PokemonTypeDetailDtoFromJson(Map<String, dynamic> json) =>
PokemonTypeDetailDto(
name: json['name'] as String,
url: json['url'] as String,
);
PokemonSpritesDto _$PokemonSpritesDtoFromJson(Map<String, dynamic> json) =>
PokemonSpritesDto(
PokemonSpritesDto _$PokemonSpritesDtoFromJson(Map<String, dynamic> json) => PokemonSpritesDto(
front_default: json['front_default'] as String,
);

View File

@ -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,
);

View File

@ -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,

View File

@ -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(

View File

@ -98,7 +98,7 @@ class BodyState extends State<Body> {
placeholder: context.locale.search,
onChanged: (search) {
Debounce.run(
() => context.read<HomeBloc>().add(HomeLoadDataEvent(search: search)));
() => context.read<HomeBloc>().add(HomeLoadDataEvent(search: search)));
},
),
),
@ -124,36 +124,36 @@ class BodyState extends State<Body> {
BlocBuilder<HomeBloc, HomeState>(
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<LikeBloc, LikeState>(
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<LikeBloc, LikeState>(
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<HomeBloc, HomeState>(
builder: (context, state) => state.isPaginationLoading

View File

@ -33,4 +33,4 @@ class LikeBloc extends Bloc<LikeEvent, LikeState> {
emit(state.copyWith(likedIds: updatedList));
}
}
}

View File

@ -10,4 +10,4 @@ class ChangeLikeEvent extends LikeEvent {
final String id;
const ChangeLikeEvent(this.id);
}
}

View File

@ -11,4 +11,4 @@ class LikeState extends Equatable {
@override
List<Object?> get props => [likedIds];
}
}

View File

@ -14,4 +14,4 @@ class LocaleBloc extends Bloc<LocaleEvent, LocaleState> {
.firstWhere((e) => e.languageCode != state.currentLocale.languageCode);
emit(state.copyWith(currentLocale: toChange));
}
}
}

View File

@ -4,4 +4,4 @@ abstract class LocaleEvent {
class ChangeLocaleEvent extends LocaleEvent {
const ChangeLocaleEvent();
}
}

View File

@ -12,4 +12,4 @@ class LocaleState extends Equatable {
@override
List<Object?> get props => [currentLocale];
}
}

View File

@ -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,
);
}
}

View File

@ -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/