Лаба 7, локализация для доп текста карточек

This commit is contained in:
a.puchkina 2024-10-18 01:12:27 +04:00
parent 77ed129792
commit b7ab60f889
12 changed files with 112 additions and 43 deletions

View File

@ -4,6 +4,8 @@
"search": "Search",
"liked": "liked!",
"disliked": "disliked :(",
"location": "Location",
"species": "Species",
"arbEnding": "Чтобы не забыть про отсутствие запятой :)"
}

View File

@ -4,6 +4,8 @@
"search": "Поиск",
"liked": "Добавлено в понравившиеся :)",
"disliked": "Удалено из понравившегося :(",
"location": "Местоположение",
"species": "Вид",
"arbEnding": "Чтобы не забыть про отсутствие запятой :)"
}

View File

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

View File

@ -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 => 'Чтобы не забыть про отсутствие запятой :)';
}

View File

@ -15,6 +15,12 @@ class AppLocaleRu extends AppLocale {
@override
String get disliked => 'Удалено из понравившегося :(';
@override
String get location => 'Местоположение';
@override
String get species => 'Вид';
@override
String get arbEnding => 'Чтобы не забыть про отсутствие запятой :)';
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -61,7 +61,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(
@ -114,8 +114,7 @@ class _BodyState extends State<Body> {
return state.currentLocale.languageCode == 'ru'
? const SvgRu()
: const SvgUk();
}
),
}),
),
),
)
@ -147,16 +146,18 @@ class _BodyState extends State<Body> {
? _Card.fromData(
data,
onLike: _onLike,
isLiked: likeState.likedIds?.contains(data.id.toString()) == true,
onTap: () => _navToDetails(context, data),
isLiked: likeState.likedIds?.contains(
data.id.toString()) ==
true,
onTap: () =>
_navToDetails(context, data),
)
: const SizedBox.shrink();
},
),
),
);
}
),
}),
),
BlocBuilder<HomeBloc, HomeState>(
builder: (context, state) => state.isPaginationLoading
@ -186,7 +187,7 @@ class _BodyState extends State<Body> {
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),
@ -198,7 +199,7 @@ class _BodyState extends State<Body> {
void _onLike(String? id, String title, bool isLiked) {
if (id != null) {
context.read<LikeBloc>().add(ChangeLikeEvent(id));
_showSnackBar(context, title, isLiked);
_showSnackBar(context, title, !isLiked);
}
}
}

View File

@ -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"',
CardData(
'Бенто-торт "Material Girl"',
descriptionText: 'Главное какой fabric, какой material',
imageUrl: 'https://i.pinimg.com/736x/f5/88/0c/f5880cc5b09e602c1849d4093d17eb8e.jpg'),
imageUrl:
'https://i.pinimg.com/736x/f5/88/0c/f5880cc5b09e602c1849d4093d17eb8e.jpg',
speciesText: '',
locationText: '',
),
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: '',
),
]);
}