diff --git a/l10n/app_en.arb b/l10n/app_en.arb index a01051c..b182259 100644 --- a/l10n/app_en.arb +++ b/l10n/app_en.arb @@ -4,6 +4,8 @@ "search": "Search", "liked": "liked!", "disliked": "disliked :(", + "location": "Location", + "species": "Species", "arbEnding": "Чтобы не забыть про отсутствие запятой :)" } \ No newline at end of file diff --git a/l10n/app_ru.arb b/l10n/app_ru.arb index c00dd02..7aec6be 100644 --- a/l10n/app_ru.arb +++ b/l10n/app_ru.arb @@ -4,6 +4,8 @@ "search": "Поиск", "liked": "Добавлено в понравившиеся :)", "disliked": "Удалено из понравившегося :(", + "location": "Местоположение", + "species": "Вид", "arbEnding": "Чтобы не забыть про отсутствие запятой :)" } \ 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 bb28342..dc004b6 100644 --- a/lib/components/locale/l10n/app_locale.dart +++ b/lib/components/locale/l10n/app_locale.dart @@ -113,6 +113,18 @@ abstract class AppLocale { /// **'Удалено из понравившегося :('** String get disliked; + /// No description provided for @location. + /// + /// In ru, this message translates to: + /// **'Местоположение'** + String get location; + + /// No description provided for @species. + /// + /// In ru, this message translates to: + /// **'Вид'** + String get species; + /// No description provided for @arbEnding. /// /// In ru, this message translates to: diff --git a/lib/components/locale/l10n/app_locale_en.dart b/lib/components/locale/l10n/app_locale_en.dart index 599548c..309e9df 100644 --- a/lib/components/locale/l10n/app_locale_en.dart +++ b/lib/components/locale/l10n/app_locale_en.dart @@ -15,6 +15,12 @@ class AppLocaleEn extends AppLocale { @override String get disliked => 'disliked :('; + @override + String get location => 'Location'; + + @override + String get species => 'Species'; + @override String get arbEnding => 'Чтобы не забыть про отсутствие запятой :)'; } diff --git a/lib/components/locale/l10n/app_locale_ru.dart b/lib/components/locale/l10n/app_locale_ru.dart index fbd2661..8c0b4d3 100644 --- a/lib/components/locale/l10n/app_locale_ru.dart +++ b/lib/components/locale/l10n/app_locale_ru.dart @@ -15,6 +15,12 @@ class AppLocaleRu extends AppLocale { @override String get disliked => 'Удалено из понравившегося :('; + @override + String get location => 'Местоположение'; + + @override + String get species => 'Вид'; + @override String get arbEnding => 'Чтобы не забыть про отсутствие запятой :)'; } diff --git a/lib/data/mappers/characters_mapper.dart b/lib/data/mappers/characters_mapper.dart index 7661378..59bbf05 100644 --- a/lib/data/mappers/characters_mapper.dart +++ b/lib/data/mappers/characters_mapper.dart @@ -17,6 +17,8 @@ extension CharacterDataDtoToModel on CharacterDataDto { attributes?.name ?? 'UNKNOWN', imageUrl: attributes?.image ?? _imagePlaceholder, descriptionText: _makeDescriptionText(attributes?.born, attributes?.died), + speciesText: '', + locationText: '', ); String _makeDescriptionText(String? born, String? died) { diff --git a/lib/data/mappers/r&m_characters_mapper.dart b/lib/data/mappers/r&m_characters_mapper.dart index c32d691..09c8d76 100644 --- a/lib/data/mappers/r&m_characters_mapper.dart +++ b/lib/data/mappers/r&m_characters_mapper.dart @@ -9,9 +9,10 @@ extension RandMCharacterDataDtoMapper on RandMCharacterDataDto { CardData toDomain() => CardData( name ?? 'UNKNOWN', imageUrl: image ?? _imagePlaceholder, - descriptionText: - 'Местоположение:\n${location?.name ?? 'unknown'}\n\nВид:\n${species ?? 'unknown'}', + descriptionText: '', id: id, + speciesText: species ?? 'unknown', + locationText: location?.name ?? 'unknown', ); } diff --git a/lib/domain/models/card.dart b/lib/domain/models/card.dart index 7b4bf1d..0cab566 100644 --- a/lib/domain/models/card.dart +++ b/lib/domain/models/card.dart @@ -4,6 +4,8 @@ class CardData { final String text; final IconData icon; final String descriptionText; + final String locationText; + final String speciesText; final String? imageUrl; final int? id; @@ -11,6 +13,8 @@ class CardData { this.text, { this.icon = Icons.bookmark_border, required this.descriptionText, + required this.locationText, + required this.speciesText, this.imageUrl, this.id, }); diff --git a/lib/presentation/details_page/details_page.dart b/lib/presentation/details_page/details_page.dart index 82f33af..dcf6017 100644 --- a/lib/presentation/details_page/details_page.dart +++ b/lib/presentation/details_page/details_page.dart @@ -1,3 +1,4 @@ +import 'package:app/components/extensions/context_x.dart'; import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; import 'package:app/domain/models/card.dart'; @@ -34,7 +35,8 @@ class DetailsPage extends StatelessWidget { Padding( padding: const EdgeInsets.all(9.0), child: Text( - data.descriptionText, + '${context.locale.location}:\n${data.locationText}\n\n' + '${context.locale.species}:\n${data.speciesText}', style: Theme.of(context).textTheme.bodyLarge, ), ) diff --git a/lib/presentation/home_page/card.dart b/lib/presentation/home_page/card.dart index d900907..d920b7e 100644 --- a/lib/presentation/home_page/card.dart +++ b/lib/presentation/home_page/card.dart @@ -6,6 +6,8 @@ class _Card extends StatelessWidget { final String text; final IconData icon; final String descriptionText; + final String locationText; + final String speciesText; final String? imageUrl; final OnLikeCallBack onLike; final VoidCallback? onTap; @@ -15,6 +17,8 @@ class _Card extends StatelessWidget { const _Card(this.text, { this.icon = Icons.bookmark_border, required this.descriptionText, + required this.locationText, + required this.speciesText, this.imageUrl, this.onLike, this.onTap, @@ -30,6 +34,8 @@ class _Card extends StatelessWidget { _Card( data.text, descriptionText: data.descriptionText, + locationText: data.locationText, + speciesText: data.speciesText, icon: data.icon, imageUrl: data.imageUrl, onLike: onLike, @@ -88,6 +94,11 @@ class _Card extends StatelessWidget { .textTheme .headlineSmall, ), + Text( + '${context.locale.location}:\n${locationText}\n\n' + '${context.locale.species}: ${speciesText}', + style: Theme.of(context).textTheme.bodyMedium, + ) ], ), ), diff --git a/lib/presentation/home_page/home_page.dart b/lib/presentation/home_page/home_page.dart index 46d2b45..dd1cac5 100644 --- a/lib/presentation/home_page/home_page.dart +++ b/lib/presentation/home_page/home_page.dart @@ -61,7 +61,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( @@ -110,12 +110,11 @@ class _BodyState extends State { child: Padding( padding: const EdgeInsets.only(right: 12), child: BlocBuilder( - builder: (context, state) { - return state.currentLocale.languageCode == 'ru' - ? const SvgRu() - : const SvgUk(); - } - ), + builder: (context, state) { + return state.currentLocale.languageCode == 'ru' + ? const SvgRu() + : const SvgUk(); + }), ), ), ) @@ -133,30 +132,32 @@ class _BodyState extends State { : state.isLoading ? const CircularProgressIndicator() : BlocBuilder( - builder: (context, 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.toString()) == true, - onTap: () => _navToDetails(context, data), - ) - : const SizedBox.shrink(); - }, - ), + 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.toString()) == + true, + onTap: () => + _navToDetails(context, data), + ) + : const SizedBox.shrink(); + }, ), - ); - } - ), + ), + ); + }), ), BlocBuilder( builder: (context, state) => state.isPaginationLoading @@ -186,7 +187,7 @@ class _BodyState extends State { WidgetsBinding.instance.addPostFrameCallback((_) { ScaffoldMessenger.of(context).showSnackBar(SnackBar( content: Text( - '$title ${isLiked ? context.locale.disliked : context.locale.liked}', + '$title ${isLiked ? context.locale.liked : context.locale.disliked}', style: Theme.of(context).textTheme.bodyLarge, ), backgroundColor: Color(0xFFFFFFFF), @@ -196,9 +197,9 @@ class _BodyState extends State { } void _onLike(String? id, String title, bool isLiked) { - if (id != null){ + if (id != null) { context.read().add(ChangeLikeEvent(id)); - _showSnackBar(context, title, isLiked); + _showSnackBar(context, title, !isLiked); } } } diff --git a/lib/repositories/mock_repository.dart b/lib/repositories/mock_repository.dart index dc525b3..f2eb08b 100644 --- a/lib/repositories/mock_repository.dart +++ b/lib/repositories/mock_repository.dart @@ -10,30 +10,50 @@ class MockRepository extends ApiInterface { CardData( descriptionText: 'И давно тебе 17?', 'Бенто-торт "Сумерки"', - imageUrl: 'https://i.pinimg.com/736x/ef/5a/80/ef5a80844de4afb19750d67f1f5be04d.jpg', + imageUrl: + 'https://i.pinimg.com/736x/ef/5a/80/ef5a80844de4afb19750d67f1f5be04d.jpg', + speciesText: '', + locationText: '', + ), + CardData( + 'Бенто-торт "Material Girl"', + descriptionText: 'Главное какой fabric, какой material', + imageUrl: + 'https://i.pinimg.com/736x/f5/88/0c/f5880cc5b09e602c1849d4093d17eb8e.jpg', + speciesText: '', + locationText: '', ), - CardData('Бенто-торт "Material Girl"', - descriptionText: 'Главное какой fabric, какой material', - imageUrl: 'https://i.pinimg.com/736x/f5/88/0c/f5880cc5b09e602c1849d4093d17eb8e.jpg'), CardData( 'Бенто-торт "Шрек"', descriptionText: 'Somebody once told me the world is gonna roll me', - imageUrl: 'https://i.pinimg.com/736x/a9/0d/fb/a90dfb9dfe3b4f4e1c5ce3cb99847a1e.jpg', + imageUrl: + 'https://i.pinimg.com/736x/a9/0d/fb/a90dfb9dfe3b4f4e1c5ce3cb99847a1e.jpg', + speciesText: '', + locationText: '', ), CardData( 'Бенто-торт "Дурак"', descriptionText: 'Сам дурак', - imageUrl: 'https://i.pinimg.com/564x/11/87/8a/11878a2f6a0c5d26e38ce68cbbe21337.jpg', + imageUrl: + 'https://i.pinimg.com/564x/11/87/8a/11878a2f6a0c5d26e38ce68cbbe21337.jpg', + speciesText: '', + locationText: '', ), CardData( 'Бенто-торт "Совунья"', descriptionText: 'Я просто смешариков люблю', - imageUrl: 'https://i.pinimg.com/564x/85/61/d2/8561d2b601fe9eb72c4e2031bbb6ba24.jpg', + imageUrl: + 'https://i.pinimg.com/564x/85/61/d2/8561d2b601fe9eb72c4e2031bbb6ba24.jpg', + speciesText: '', + locationText: '', ), CardData( 'Бенто-торт "В смысле 28?"', descriptionText: 'Напишем любой возраст (или срок)', - imageUrl: 'https://i.pinimg.com/564x/ae/76/0a/ae760af69d9a0c12938753a372112ee4.jpg', + imageUrl: + 'https://i.pinimg.com/564x/ae/76/0a/ae760af69d9a0c12938753a372112ee4.jpg', + speciesText: '', + locationText: '', ), ]); }