From b930d28d54e292ddfcc325cd2ac2a164e1dd39a9 Mon Sep 17 00:00:00 2001 From: sardq Date: Thu, 17 Oct 2024 16:31:39 +0400 Subject: [PATCH] 7 lab final --- l10n/app_en.arb | 2 +- lib/components/locale/l10n/app_locale_en.dart | 2 +- lib/data/dtos/mangas_dto.dart | 3 ++- lib/data/dtos/mangas_dto.g.dart | 2 +- lib/data/mappers/mangas_mapper.dart | 1 + lib/presentation/home_page/home_page.dart | 9 +++++++-- lib/presentation/locale_bloc/locale_state.g.dart | 12 +++++++----- pubspec.lock | 2 +- pubspec.yaml | 1 + 9 files changed, 22 insertions(+), 12 deletions(-) diff --git a/l10n/app_en.arb b/l10n/app_en.arb index ef8191e..163cefe 100644 --- a/l10n/app_en.arb +++ b/l10n/app_en.arb @@ -3,6 +3,6 @@ "search": "Search", "liked": "liked!", - "unliked": "unliked" + "disliked": "unliked" } diff --git a/lib/components/locale/l10n/app_locale_en.dart b/lib/components/locale/l10n/app_locale_en.dart index fdb09c6..eb604fd 100644 --- a/lib/components/locale/l10n/app_locale_en.dart +++ b/lib/components/locale/l10n/app_locale_en.dart @@ -11,5 +11,5 @@ class AppLocaleEn extends AppLocale { String get liked => 'liked!'; @override - String get disliked => 'разонравился'; + String get disliked => 'unliked'; } diff --git a/lib/data/dtos/mangas_dto.dart b/lib/data/dtos/mangas_dto.dart index 7d5397d..44c3abc 100644 --- a/lib/data/dtos/mangas_dto.dart +++ b/lib/data/dtos/mangas_dto.dart @@ -28,7 +28,8 @@ class MangaPaginationDto { @JsonSerializable(createToJson: false) class MangaDataDto { - final String? id; + @JsonKey(name: "mal_id") + final int? id; final String? type; final String? title; final String? status; diff --git a/lib/data/dtos/mangas_dto.g.dart b/lib/data/dtos/mangas_dto.g.dart index ee18790..d19c7a5 100644 --- a/lib/data/dtos/mangas_dto.g.dart +++ b/lib/data/dtos/mangas_dto.g.dart @@ -31,7 +31,7 @@ MangaDataDto _$MangaDataDtoFromJson(Map json) => MangaDataDto( json['images'] == null ? null : MangaDataImagesDto.fromJson(json['images'] as Map), - id: json['id'] as String?, + id: (json['mal_id'] as num?)?.toInt(), type: json['type'] as String?, ); diff --git a/lib/data/mappers/mangas_mapper.dart b/lib/data/mappers/mangas_mapper.dart index ac378e1..b4b0eed 100644 --- a/lib/data/mappers/mangas_mapper.dart +++ b/lib/data/mappers/mangas_mapper.dart @@ -6,6 +6,7 @@ extension MangaDataDtoMapper on MangaDataDto { CardData toDomain() => CardData( title ?? 'UNKNOWN', imageUrl: images?.jpg?.image_url, + id: id.toString(), descriptionText: 'Статус: ${status}. Рейтинг: ${score}. Людей поставило оценку: ${scored_by}', ); diff --git a/lib/presentation/home_page/home_page.dart b/lib/presentation/home_page/home_page.dart index 9272309..00711e8 100644 --- a/lib/presentation/home_page/home_page.dart +++ b/lib/presentation/home_page/home_page.dart @@ -1,5 +1,6 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_app/components/extension/context_x.dart'; import 'package:flutter_app/components/utils/debounce.dart'; import 'package:flutter_app/data/repositories/manga_repository.dart'; import 'package:flutter_app/presentation/details_page/details_page.dart'; @@ -63,7 +64,7 @@ class _BodyState extends State { } void _onNextPageListener() { - if (scrollController.offset > scrollController.position.maxScrollExtent) { + if (scrollController.offset >= scrollController.position.maxScrollExtent) { final bloc = context.read(); if (!bloc.state.isPaginationLoading) { bloc.add(HomeLoadDataEvent( @@ -84,6 +85,7 @@ class _BodyState extends State { var data = MangaRepository().loadData(); void _onLike(String? id, String title, bool isLiked) { + print("$id $title, $isLiked"); if (id != null) { context.read().add(ChangeLikeEvent(id)); _showSnackBar(context, title, !isLiked); @@ -94,7 +96,7 @@ class _BodyState extends State { WidgetsBinding.instance.addPostFrameCallback((_) { ScaffoldMessenger.of(context).showSnackBar(SnackBar( content: Text( - 'Лайк на $title ${isLiked ? 'поставлен' : 'убран'}', + ' ${isLiked ? context.locale.liked : context.locale.disliked} $title', style: Theme.of(context).textTheme.bodyLarge, ), backgroundColor: Colors.orangeAccent, @@ -163,6 +165,9 @@ class _BodyState extends State { return data != null ? _Card.fromData( data, + isLiked: likeState.likedIds + ?.contains(data.id) == + true, onLike: _onLike, onTap: () => _navToDetails(context, data), diff --git a/lib/presentation/locale_bloc/locale_state.g.dart b/lib/presentation/locale_bloc/locale_state.g.dart index 23ee063..e374db6 100644 --- a/lib/presentation/locale_bloc/locale_state.g.dart +++ b/lib/presentation/locale_bloc/locale_state.g.dart @@ -27,7 +27,8 @@ class _$LocaleStateCWProxyImpl implements _$LocaleStateCWProxy { final LocaleState _value; @override - LocaleState currentLocale(Locale currentLocale) => this(currentLocale: currentLocale); + LocaleState currentLocale(Locale currentLocale) => + this(currentLocale: currentLocale); @override @@ -41,10 +42,11 @@ 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.lock b/pubspec.lock index 0a5e5d5..7ffbd6a 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -178,7 +178,7 @@ packages: source: hosted version: "3.1.1" copy_with_extension: - dependency: transitive + dependency: "direct main" description: name: copy_with_extension sha256: fbcf890b0c34aedf0894f91a11a579994b61b4e04080204656b582708b5b1125 diff --git a/pubspec.yaml b/pubspec.yaml index 47825a9..c790b80 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -20,6 +20,7 @@ dependencies: equatable: ^2.0.5 flutter_bloc: ^8.1.5 copy_with_extension_gen: ^5.0.4 + copy_with_extension: ^5.0.4 flutter_localizations: sdk: flutter