7 lab final

This commit is contained in:
sardq 2024-10-17 16:31:39 +04:00
parent c7ed4b4e5c
commit b930d28d54
9 changed files with 22 additions and 12 deletions

View File

@ -3,6 +3,6 @@
"search": "Search", "search": "Search",
"liked": "liked!", "liked": "liked!",
"unliked": "unliked" "disliked": "unliked"
} }

View File

@ -11,5 +11,5 @@ class AppLocaleEn extends AppLocale {
String get liked => 'liked!'; String get liked => 'liked!';
@override @override
String get disliked => 'разонравился'; String get disliked => 'unliked';
} }

View File

@ -28,7 +28,8 @@ class MangaPaginationDto {
@JsonSerializable(createToJson: false) @JsonSerializable(createToJson: false)
class MangaDataDto { class MangaDataDto {
final String? id; @JsonKey(name: "mal_id")
final int? id;
final String? type; final String? type;
final String? title; final String? title;
final String? status; final String? status;

View File

@ -31,7 +31,7 @@ MangaDataDto _$MangaDataDtoFromJson(Map<String, dynamic> json) => MangaDataDto(
json['images'] == null json['images'] == null
? null ? null
: MangaDataImagesDto.fromJson(json['images'] as Map<String, dynamic>), : MangaDataImagesDto.fromJson(json['images'] as Map<String, dynamic>),
id: json['id'] as String?, id: (json['mal_id'] as num?)?.toInt(),
type: json['type'] as String?, type: json['type'] as String?,
); );

View File

@ -6,6 +6,7 @@ extension MangaDataDtoMapper on MangaDataDto {
CardData toDomain() => CardData( CardData toDomain() => CardData(
title ?? 'UNKNOWN', title ?? 'UNKNOWN',
imageUrl: images?.jpg?.image_url, imageUrl: images?.jpg?.image_url,
id: id.toString(),
descriptionText: descriptionText:
'Статус: ${status}. Рейтинг: ${score}. Людей поставило оценку: ${scored_by}', 'Статус: ${status}. Рейтинг: ${score}. Людей поставило оценку: ${scored_by}',
); );

View File

@ -1,5 +1,6 @@
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.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/components/utils/debounce.dart';
import 'package:flutter_app/data/repositories/manga_repository.dart'; import 'package:flutter_app/data/repositories/manga_repository.dart';
import 'package:flutter_app/presentation/details_page/details_page.dart'; import 'package:flutter_app/presentation/details_page/details_page.dart';
@ -63,7 +64,7 @@ class _BodyState extends State<Body> {
} }
void _onNextPageListener() { void _onNextPageListener() {
if (scrollController.offset > scrollController.position.maxScrollExtent) { if (scrollController.offset >= scrollController.position.maxScrollExtent) {
final bloc = context.read<HomeBloc>(); final bloc = context.read<HomeBloc>();
if (!bloc.state.isPaginationLoading) { if (!bloc.state.isPaginationLoading) {
bloc.add(HomeLoadDataEvent( bloc.add(HomeLoadDataEvent(
@ -84,6 +85,7 @@ class _BodyState extends State<Body> {
var data = MangaRepository().loadData(); var data = MangaRepository().loadData();
void _onLike(String? id, String title, bool isLiked) { void _onLike(String? id, String title, bool isLiked) {
print("$id $title, $isLiked");
if (id != null) { if (id != null) {
context.read<LikeBloc>().add(ChangeLikeEvent(id)); context.read<LikeBloc>().add(ChangeLikeEvent(id));
_showSnackBar(context, title, !isLiked); _showSnackBar(context, title, !isLiked);
@ -94,7 +96,7 @@ class _BodyState extends State<Body> {
WidgetsBinding.instance.addPostFrameCallback((_) { WidgetsBinding.instance.addPostFrameCallback((_) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar( ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: Text( content: Text(
'Лайк на $title ${isLiked ? 'поставлен' : 'убран'}', ' ${isLiked ? context.locale.liked : context.locale.disliked} $title',
style: Theme.of(context).textTheme.bodyLarge, style: Theme.of(context).textTheme.bodyLarge,
), ),
backgroundColor: Colors.orangeAccent, backgroundColor: Colors.orangeAccent,
@ -163,6 +165,9 @@ class _BodyState extends State<Body> {
return data != null return data != null
? _Card.fromData( ? _Card.fromData(
data, data,
isLiked: likeState.likedIds
?.contains(data.id) ==
true,
onLike: _onLike, onLike: _onLike,
onTap: () => onTap: () =>
_navToDetails(context, data), _navToDetails(context, data),

View File

@ -27,7 +27,8 @@ class _$LocaleStateCWProxyImpl implements _$LocaleStateCWProxy {
final LocaleState _value; final LocaleState _value;
@override @override
LocaleState currentLocale(Locale currentLocale) => this(currentLocale: currentLocale); LocaleState currentLocale(Locale currentLocale) =>
this(currentLocale: currentLocale);
@override @override
@ -41,7 +42,8 @@ class _$LocaleStateCWProxyImpl implements _$LocaleStateCWProxy {
Object? currentLocale = const $CopyWithPlaceholder(), Object? currentLocale = const $CopyWithPlaceholder(),
}) { }) {
return LocaleState( return LocaleState(
currentLocale: currentLocale == const $CopyWithPlaceholder() || currentLocale == null currentLocale:
currentLocale == const $CopyWithPlaceholder() || currentLocale == null
? _value.currentLocale ? _value.currentLocale
// ignore: cast_nullable_to_non_nullable // ignore: cast_nullable_to_non_nullable
: currentLocale as Locale, : currentLocale as Locale,

View File

@ -178,7 +178,7 @@ packages:
source: hosted source: hosted
version: "3.1.1" version: "3.1.1"
copy_with_extension: copy_with_extension:
dependency: transitive dependency: "direct main"
description: description:
name: copy_with_extension name: copy_with_extension
sha256: fbcf890b0c34aedf0894f91a11a579994b61b4e04080204656b582708b5b1125 sha256: fbcf890b0c34aedf0894f91a11a579994b61b4e04080204656b582708b5b1125

View File

@ -20,6 +20,7 @@ dependencies:
equatable: ^2.0.5 equatable: ^2.0.5
flutter_bloc: ^8.1.5 flutter_bloc: ^8.1.5
copy_with_extension_gen: ^5.0.4 copy_with_extension_gen: ^5.0.4
copy_with_extension: ^5.0.4
flutter_localizations: flutter_localizations:
sdk: flutter sdk: flutter