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",
"liked": "liked!",
"unliked": "unliked"
"disliked": "unliked"
}

View File

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

View File

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

View File

@ -31,7 +31,7 @@ MangaDataDto _$MangaDataDtoFromJson(Map<String, dynamic> json) => MangaDataDto(
json['images'] == null
? null
: 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?,
);

View File

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

View File

@ -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<Body> {
}
void _onNextPageListener() {
if (scrollController.offset > scrollController.position.maxScrollExtent) {
if (scrollController.offset >= scrollController.position.maxScrollExtent) {
final bloc = context.read<HomeBloc>();
if (!bloc.state.isPaginationLoading) {
bloc.add(HomeLoadDataEvent(
@ -84,6 +85,7 @@ class _BodyState extends State<Body> {
var data = MangaRepository().loadData();
void _onLike(String? id, String title, bool isLiked) {
print("$id $title, $isLiked");
if (id != null) {
context.read<LikeBloc>().add(ChangeLikeEvent(id));
_showSnackBar(context, title, !isLiked);
@ -94,7 +96,7 @@ class _BodyState extends State<Body> {
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<Body> {
return data != null
? _Card.fromData(
data,
isLiked: likeState.likedIds
?.contains(data.id) ==
true,
onLike: _onLike,
onTap: () =>
_navToDetails(context, data),

View File

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

View File

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

View File

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