Лаба 7, локализация для доп текста карточек
This commit is contained in:
parent
77ed129792
commit
b7ab60f889
@ -4,6 +4,8 @@
|
|||||||
"search": "Search",
|
"search": "Search",
|
||||||
"liked": "liked!",
|
"liked": "liked!",
|
||||||
"disliked": "disliked :(",
|
"disliked": "disliked :(",
|
||||||
|
"location": "Location",
|
||||||
|
"species": "Species",
|
||||||
|
|
||||||
"arbEnding": "Чтобы не забыть про отсутствие запятой :)"
|
"arbEnding": "Чтобы не забыть про отсутствие запятой :)"
|
||||||
}
|
}
|
@ -4,6 +4,8 @@
|
|||||||
"search": "Поиск",
|
"search": "Поиск",
|
||||||
"liked": "Добавлено в понравившиеся :)",
|
"liked": "Добавлено в понравившиеся :)",
|
||||||
"disliked": "Удалено из понравившегося :(",
|
"disliked": "Удалено из понравившегося :(",
|
||||||
|
"location": "Местоположение",
|
||||||
|
"species": "Вид",
|
||||||
|
|
||||||
"arbEnding": "Чтобы не забыть про отсутствие запятой :)"
|
"arbEnding": "Чтобы не забыть про отсутствие запятой :)"
|
||||||
}
|
}
|
@ -113,6 +113,18 @@ abstract class AppLocale {
|
|||||||
/// **'Удалено из понравившегося :('**
|
/// **'Удалено из понравившегося :('**
|
||||||
String get disliked;
|
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.
|
/// No description provided for @arbEnding.
|
||||||
///
|
///
|
||||||
/// In ru, this message translates to:
|
/// In ru, this message translates to:
|
||||||
|
@ -15,6 +15,12 @@ class AppLocaleEn extends AppLocale {
|
|||||||
@override
|
@override
|
||||||
String get disliked => 'disliked :(';
|
String get disliked => 'disliked :(';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get location => 'Location';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get species => 'Species';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get arbEnding => 'Чтобы не забыть про отсутствие запятой :)';
|
String get arbEnding => 'Чтобы не забыть про отсутствие запятой :)';
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,12 @@ class AppLocaleRu extends AppLocale {
|
|||||||
@override
|
@override
|
||||||
String get disliked => 'Удалено из понравившегося :(';
|
String get disliked => 'Удалено из понравившегося :(';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get location => 'Местоположение';
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get species => 'Вид';
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get arbEnding => 'Чтобы не забыть про отсутствие запятой :)';
|
String get arbEnding => 'Чтобы не забыть про отсутствие запятой :)';
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,8 @@ extension CharacterDataDtoToModel on CharacterDataDto {
|
|||||||
attributes?.name ?? 'UNKNOWN',
|
attributes?.name ?? 'UNKNOWN',
|
||||||
imageUrl: attributes?.image ?? _imagePlaceholder,
|
imageUrl: attributes?.image ?? _imagePlaceholder,
|
||||||
descriptionText: _makeDescriptionText(attributes?.born, attributes?.died),
|
descriptionText: _makeDescriptionText(attributes?.born, attributes?.died),
|
||||||
|
speciesText: '',
|
||||||
|
locationText: '',
|
||||||
);
|
);
|
||||||
|
|
||||||
String _makeDescriptionText(String? born, String? died) {
|
String _makeDescriptionText(String? born, String? died) {
|
||||||
|
@ -9,9 +9,10 @@ extension RandMCharacterDataDtoMapper on RandMCharacterDataDto {
|
|||||||
CardData toDomain() => CardData(
|
CardData toDomain() => CardData(
|
||||||
name ?? 'UNKNOWN',
|
name ?? 'UNKNOWN',
|
||||||
imageUrl: image ?? _imagePlaceholder,
|
imageUrl: image ?? _imagePlaceholder,
|
||||||
descriptionText:
|
descriptionText: '',
|
||||||
'Местоположение:\n${location?.name ?? 'unknown'}\n\nВид:\n${species ?? 'unknown'}',
|
|
||||||
id: id,
|
id: id,
|
||||||
|
speciesText: species ?? 'unknown',
|
||||||
|
locationText: location?.name ?? 'unknown',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,8 @@ class CardData {
|
|||||||
final String text;
|
final String text;
|
||||||
final IconData icon;
|
final IconData icon;
|
||||||
final String descriptionText;
|
final String descriptionText;
|
||||||
|
final String locationText;
|
||||||
|
final String speciesText;
|
||||||
final String? imageUrl;
|
final String? imageUrl;
|
||||||
final int? id;
|
final int? id;
|
||||||
|
|
||||||
@ -11,6 +13,8 @@ class CardData {
|
|||||||
this.text, {
|
this.text, {
|
||||||
this.icon = Icons.bookmark_border,
|
this.icon = Icons.bookmark_border,
|
||||||
required this.descriptionText,
|
required this.descriptionText,
|
||||||
|
required this.locationText,
|
||||||
|
required this.speciesText,
|
||||||
this.imageUrl,
|
this.imageUrl,
|
||||||
this.id,
|
this.id,
|
||||||
});
|
});
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import 'package:app/components/extensions/context_x.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:app/domain/models/card.dart';
|
import 'package:app/domain/models/card.dart';
|
||||||
@ -34,7 +35,8 @@ class DetailsPage extends StatelessWidget {
|
|||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.all(9.0),
|
padding: const EdgeInsets.all(9.0),
|
||||||
child: Text(
|
child: Text(
|
||||||
data.descriptionText,
|
'${context.locale.location}:\n${data.locationText}\n\n'
|
||||||
|
'${context.locale.species}:\n${data.speciesText}',
|
||||||
style: Theme.of(context).textTheme.bodyLarge,
|
style: Theme.of(context).textTheme.bodyLarge,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -6,6 +6,8 @@ class _Card extends StatelessWidget {
|
|||||||
final String text;
|
final String text;
|
||||||
final IconData icon;
|
final IconData icon;
|
||||||
final String descriptionText;
|
final String descriptionText;
|
||||||
|
final String locationText;
|
||||||
|
final String speciesText;
|
||||||
final String? imageUrl;
|
final String? imageUrl;
|
||||||
final OnLikeCallBack onLike;
|
final OnLikeCallBack onLike;
|
||||||
final VoidCallback? onTap;
|
final VoidCallback? onTap;
|
||||||
@ -15,6 +17,8 @@ class _Card extends StatelessWidget {
|
|||||||
const _Card(this.text, {
|
const _Card(this.text, {
|
||||||
this.icon = Icons.bookmark_border,
|
this.icon = Icons.bookmark_border,
|
||||||
required this.descriptionText,
|
required this.descriptionText,
|
||||||
|
required this.locationText,
|
||||||
|
required this.speciesText,
|
||||||
this.imageUrl,
|
this.imageUrl,
|
||||||
this.onLike,
|
this.onLike,
|
||||||
this.onTap,
|
this.onTap,
|
||||||
@ -30,6 +34,8 @@ class _Card extends StatelessWidget {
|
|||||||
_Card(
|
_Card(
|
||||||
data.text,
|
data.text,
|
||||||
descriptionText: data.descriptionText,
|
descriptionText: data.descriptionText,
|
||||||
|
locationText: data.locationText,
|
||||||
|
speciesText: data.speciesText,
|
||||||
icon: data.icon,
|
icon: data.icon,
|
||||||
imageUrl: data.imageUrl,
|
imageUrl: data.imageUrl,
|
||||||
onLike: onLike,
|
onLike: onLike,
|
||||||
@ -88,6 +94,11 @@ class _Card extends StatelessWidget {
|
|||||||
.textTheme
|
.textTheme
|
||||||
.headlineSmall,
|
.headlineSmall,
|
||||||
),
|
),
|
||||||
|
Text(
|
||||||
|
'${context.locale.location}:\n${locationText}\n\n'
|
||||||
|
'${context.locale.species}: ${speciesText}',
|
||||||
|
style: Theme.of(context).textTheme.bodyMedium,
|
||||||
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
@ -61,7 +61,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(
|
||||||
@ -110,12 +110,11 @@ class _BodyState extends State<Body> {
|
|||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.only(right: 12),
|
padding: const EdgeInsets.only(right: 12),
|
||||||
child: BlocBuilder<LocaleBloc, LocaleState>(
|
child: BlocBuilder<LocaleBloc, LocaleState>(
|
||||||
builder: (context, state) {
|
builder: (context, state) {
|
||||||
return state.currentLocale.languageCode == 'ru'
|
return state.currentLocale.languageCode == 'ru'
|
||||||
? const SvgRu()
|
? const SvgRu()
|
||||||
: const SvgUk();
|
: const SvgUk();
|
||||||
}
|
}),
|
||||||
),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@ -133,30 +132,32 @@ class _BodyState extends State<Body> {
|
|||||||
: state.isLoading
|
: state.isLoading
|
||||||
? const CircularProgressIndicator()
|
? const CircularProgressIndicator()
|
||||||
: BlocBuilder<LikeBloc, LikeState>(
|
: BlocBuilder<LikeBloc, LikeState>(
|
||||||
builder: (context, likeState) {
|
builder: (context, likeState) {
|
||||||
return Expanded(
|
return Expanded(
|
||||||
child: RefreshIndicator(
|
child: RefreshIndicator(
|
||||||
onRefresh: _onRefresh,
|
onRefresh: _onRefresh,
|
||||||
child: ListView.builder(
|
child: ListView.builder(
|
||||||
controller: scrollController,
|
controller: scrollController,
|
||||||
padding: EdgeInsets.zero,
|
padding: EdgeInsets.zero,
|
||||||
itemCount: state.data?.data?.length ?? 0,
|
itemCount: state.data?.data?.length ?? 0,
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
final data = state.data?.data?[index];
|
final data = state.data?.data?[index];
|
||||||
return data != null
|
return data != null
|
||||||
? _Card.fromData(
|
? _Card.fromData(
|
||||||
data,
|
data,
|
||||||
onLike: _onLike,
|
onLike: _onLike,
|
||||||
isLiked: likeState.likedIds?.contains(data.id.toString()) == true,
|
isLiked: likeState.likedIds?.contains(
|
||||||
onTap: () => _navToDetails(context, data),
|
data.id.toString()) ==
|
||||||
)
|
true,
|
||||||
: const SizedBox.shrink();
|
onTap: () =>
|
||||||
},
|
_navToDetails(context, data),
|
||||||
),
|
)
|
||||||
|
: const SizedBox.shrink();
|
||||||
|
},
|
||||||
),
|
),
|
||||||
);
|
),
|
||||||
}
|
);
|
||||||
),
|
}),
|
||||||
),
|
),
|
||||||
BlocBuilder<HomeBloc, HomeState>(
|
BlocBuilder<HomeBloc, HomeState>(
|
||||||
builder: (context, state) => state.isPaginationLoading
|
builder: (context, state) => state.isPaginationLoading
|
||||||
@ -186,7 +187,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 ? context.locale.disliked : context.locale.liked}',
|
'$title ${isLiked ? context.locale.liked : context.locale.disliked}',
|
||||||
style: Theme.of(context).textTheme.bodyLarge,
|
style: Theme.of(context).textTheme.bodyLarge,
|
||||||
),
|
),
|
||||||
backgroundColor: Color(0xFFFFFFFF),
|
backgroundColor: Color(0xFFFFFFFF),
|
||||||
@ -196,9 +197,9 @@ class _BodyState extends State<Body> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _onLike(String? id, String title, bool isLiked) {
|
void _onLike(String? id, String title, bool 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,30 +10,50 @@ class MockRepository extends ApiInterface {
|
|||||||
CardData(
|
CardData(
|
||||||
descriptionText: 'И давно тебе 17?',
|
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(
|
CardData(
|
||||||
'Бенто-торт "Шрек"',
|
'Бенто-торт "Шрек"',
|
||||||
descriptionText: 'Somebody once told me the world is gonna roll me',
|
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(
|
CardData(
|
||||||
'Бенто-торт "Дурак"',
|
'Бенто-торт "Дурак"',
|
||||||
descriptionText: 'Сам дурак',
|
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(
|
CardData(
|
||||||
'Бенто-торт "Совунья"',
|
'Бенто-торт "Совунья"',
|
||||||
descriptionText: 'Я просто смешариков люблю',
|
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(
|
CardData(
|
||||||
'Бенто-торт "В смысле 28?"',
|
'Бенто-торт "В смысле 28?"',
|
||||||
descriptionText: 'Напишем любой возраст (или срок)',
|
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: '',
|
||||||
),
|
),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user