в целома работает

This commit is contained in:
Галина Федоренко 2024-11-19 11:41:18 +04:00
parent dba446ccd9
commit c1d6ed3a26
16 changed files with 67 additions and 94 deletions

View File

Before

Width:  |  Height:  |  Size: 968 B

After

Width:  |  Height:  |  Size: 968 B

View File

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@ -1,5 +1,5 @@
import 'package:flutter_app/components/locale/l10n/app_locale.dart'; import 'package:flutter_app/components/locale/l10n/app_locale.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/widgets.dart';
extension LocalContextX on BuildContext { extension LocalContextX on BuildContext {
AppLocale get locale => AppLocale.of(this)!; AppLocale get locale => AppLocale.of(this)!;

View File

@ -113,18 +113,6 @@ 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:

View File

@ -2,24 +2,18 @@ import 'app_locale.dart';
// ignore_for_file: type=lint // ignore_for_file: type=lint
/// The translations for Russian (`ru`). /// The translations for English (`en`).
class AppLocaleRu extends AppLocale { class AppLocaleEn extends AppLocale {
AppLocaleRu([String locale = 'ru']) : super(locale); AppLocaleEn([String locale = 'en']) : super(locale);
@override @override
String get search => 'Поиск'; String get search => 'Search';
@override @override
String get liked => 'Добавлено в понравившиеся :)'; String get liked => 'liked!';
@override @override
String get disliked => 'Удалено из понравившегося :('; String get disliked => 'disliked :(';
@override
String get location => 'Местоположение';
@override
String get species => 'Вид';
@override @override
String get arbEnding => 'Чтобы не забыть про отсутствие запятой :)'; String get arbEnding => 'Чтобы не забыть про отсутствие запятой :)';

View File

@ -2,24 +2,18 @@ import 'app_locale.dart';
// ignore_for_file: type=lint // ignore_for_file: type=lint
/// The translations for English (`en`). /// The translations for Russian (`ru`).
class AppLocaleEn extends AppLocale { class AppLocaleRu extends AppLocale {
AppLocaleEn([String locale = 'en']) : super(locale); AppLocaleRu([String locale = 'ru']) : super(locale);
@override @override
String get search => 'Search'; String get search => 'Поиск';
@override @override
String get liked => 'liked!'; String get liked => 'Добавлено в понравившиеся :)';
@override @override
String get disliked => 'disliked :('; String get disliked => 'Удалено из понравившегося :(';
@override
String get location => 'Location';
@override
String get species => 'Species';
@override @override
String get arbEnding => 'Чтобы не забыть про отсутствие запятой :)'; String get arbEnding => 'Чтобы не забыть про отсутствие запятой :)';

View File

@ -0,0 +1,10 @@
/// Generate by [asset_generator](https://github.com/fluttercandies/flutter_asset_generator) library.
/// PLEASE DO NOT EDIT MANUALLY.
// ignore_for_file: constant_identifier_names
class R {
const R._();
static const String ASSETS_SVG_RU_SVG = 'assets/svg/ru.svg';
static const String ASSETS_SVG_UK_SVG = 'assets/svg/uk.svg';
}

View File

@ -15,8 +15,6 @@ extension ThronesCharacterDtoToModel on ThronesCharacterDto {
fullName: fullName, fullName: fullName,
imageUrl: imageUrl, imageUrl: imageUrl,
text: '', text: '',
speciesText: species ?? 'unknown',
locationText: location?.name ?? 'unknown',
); );
String _makeDescriptionText(String? title, String? family) { String _makeDescriptionText(String? title, String? family) {

View File

@ -11,8 +11,6 @@ class CardData {
final String? title; final String? title;
final String? family; final String? family;
final int? id; final int? id;
final String locationText;
final String speciesText;
CardData({ CardData({
required this.text, required this.text,
@ -25,7 +23,5 @@ class CardData {
required this.title, required this.title,
required this.family, required this.family,
this.id, this.id,
required this.locationText,
required this.speciesText,
}); });
} }

View File

@ -1,3 +1,5 @@
import 'dart:io';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_app/data/repositories/got_repository.dart'; import 'package:flutter_app/data/repositories/got_repository.dart';
import 'package:flutter_app/presentation/home_page/bloc/bloc.dart'; import 'package:flutter_app/presentation/home_page/bloc/bloc.dart';
@ -18,22 +20,6 @@ class MyApp extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
// return MaterialApp(
// title: '7 Kingdoms',
// theme: ThemeData(
// colorScheme: ColorScheme.fromSeed(seedColor: const Color.fromARGB(255, 20, 40, 150)),
// useMaterial3: true,
// ),
// home: RepositoryProvider<ThronesRepository>(
// lazy: true,
// create: (_) => ThronesRepository(),
// child: BlocProvider<HomeBloc>(
// lazy: false,
// create: (context) => HomeBloc(context.read<ThronesRepository>()),
// child: const MyHomePage(title: '7 Kingdoms'),
// ),
// ));
return BlocProvider<LocaleBloc>( return BlocProvider<LocaleBloc>(
lazy: false, lazy: false,
create: (context) => LocaleBloc((Locale(Platform.localeName))), create: (context) => LocaleBloc((Locale(Platform.localeName))),

View File

@ -1,12 +1,12 @@
import 'package:flutter/cupertino.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_svg/flutter_svg.dart';
import 'package:flutter_app/components/resources.g.dart'; import 'package:flutter_app/components/resources.g.dart';
abstract class SvgObjects { abstract class SvgObjects {
static void init() { static void init() {
final pics = <String>[ final pics = <String>[
R.ASSETS_SVG_FLAG_GB_SVGREPO_COM_SVG, R.ASSETS_SVG_RU_SVG,
R.ASSETS_SVG_FLAG_RU_SVGREPO_COM_SVG, R.ASSETS_SVG_UK_SVG,
]; ];
for (final String p in pics) { for (final String p in pics) {
final loader = SvgAssetLoader(p); final loader = SvgAssetLoader(p);
@ -20,7 +20,7 @@ class SvgRu extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return SvgPicture.asset(R.ASSETS_SVG_FLAG_RU_SVGREPO_COM_SVG); return SvgPicture.asset(R.ASSETS_SVG_RU_SVG);
} }
} }
@ -29,6 +29,6 @@ class SvgUk extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return SvgPicture.asset(R.ASSETS_SVG_FLAG_GB_SVGREPO_COM_SVG); return SvgPicture.asset(R.ASSETS_SVG_UK_SVG);
} }
} }

View File

@ -1,6 +1,6 @@
part of 'home_page.dart'; part of 'home_page.dart';
typedef OnLikeCallback = void Function(int? id, String title, bool isLiked)?; typedef OnLikeCallback = void Function(String? id, String title, bool isLiked)?;
class _Card extends StatelessWidget { class _Card extends StatelessWidget {
final String text; final String text;
@ -10,7 +10,7 @@ class _Card extends StatelessWidget {
final String? imageUrl; final String? imageUrl;
final OnLikeCallback onLike; final OnLikeCallback onLike;
final VoidCallback? onTap; final VoidCallback? onTap;
final int? id; final String? id;
final bool isLiked; final bool isLiked;
const _Card( const _Card(
@ -40,7 +40,7 @@ class _Card extends StatelessWidget {
onLike: onLike, onLike: onLike,
onTap: onTap, onTap: onTap,
isLiked: isLiked, isLiked: isLiked,
id: data.id, id: data.id.toString()
); );
@override @override

View File

@ -144,7 +144,7 @@ class _BodyState extends State<Body> {
? _Card.fromData( ? _Card.fromData(
data, data,
onLike: _onLike, onLike: _onLike,
isLiked: likeState.likedIds?.contains(data.id) == true, isLiked: likeState.likedIds?.contains(data.id.toString()) == true,
onTap: () => _navToDetails(context, data), onTap: () => _navToDetails(context, data),
) )
: const SizedBox.shrink(); : const SizedBox.shrink();
@ -181,16 +181,16 @@ 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.liked : context.locale.disliked}', '$title ${isLiked ? context.locale.disliked : context.locale.liked}',
style: Theme.of(context).textTheme.bodyLarge, style: const TextStyle(color: Colors.white),
), ),
backgroundColor: Colors.brown.shade300, backgroundColor: const Color.fromARGB(255, 20, 40, 150),
duration: const Duration(seconds: 1), duration: const Duration(seconds: 1),
)); ));
}); });
} }
void _onLike(int? 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);

View File

@ -22,10 +22,7 @@ class LikeBloc extends Bloc<LikeEvent, LikeState> {
} }
FutureOr<void> _onChangeLike(ChangeLikeEvent event, Emitter<LikeState> emit) async{ FutureOr<void> _onChangeLike(ChangeLikeEvent event, Emitter<LikeState> emit) async{
final updatedListInt = List<int>.from(state.likedIds ?? []); final updatedList = List<String>.from(state.likedIds ?? []);
print(updatedListInt);
final updatedList = updatedListInt.map((int number) => number.toString()).toList();
print(updatedList);
if (updatedList.contains(event.id.toString())) { if (updatedList.contains(event.id.toString())) {
updatedList.remove(event.id.toString()); updatedList.remove(event.id.toString());

View File

@ -7,7 +7,7 @@ class LoadLikesEvent extends LikeEvent {
} }
class ChangeLikeEvent extends LikeEvent { class ChangeLikeEvent extends LikeEvent {
final int id; final String id;
const ChangeLikeEvent(this.id); const ChangeLikeEvent(this.id);
} }

View File

@ -30,23 +30,39 @@ environment:
dependencies: dependencies:
flutter: flutter:
sdk: flutter sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^1.0.8
flutter_svg: 2.0.7
json_annotation: ^4.8.1 json_annotation: ^4.8.1
dio: ^5.4.2+1 dio: ^5.4.2+1
pretty_dio_logger: ^1.3.1 pretty_dio_logger: ^1.3.1
cupertino_icons: ^1.0.8
flutter_bloc: ^8.1.6 # BLoC
equatable: ^2.0.5 equatable: ^2.0.5
flutter_bloc: ^8.1.5
copy_with_extension_gen: ^5.0.4 copy_with_extension_gen: ^5.0.4
flutter_svg: 2.0.7
flutter_localizations: flutter_localizations:
sdk: flutter sdk: flutter
intl: ^0.19.0 intl: ^0.19.0
shared_preferences: 2.2.3 shared_preferences: 2.2.3
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:
sdk: flutter sdk: flutter
# The "flutter_lints" package below contains a set of recommended lints to
# encourage good coding practices. The lint set provided by the package is
# activated in the `analysis_options.yaml` file located at the root of your
# package. See that file for information about deactivating specific lint
# rules and activating additional ones.
build_runner: ^2.4.9 build_runner: ^2.4.9
json_serializable: ^6.7.1 json_serializable: ^6.7.1
@ -57,15 +73,8 @@ dev_dependencies:
flutter_icons: flutter_icons:
android: "ic_launcher" android: "ic_launcher"
ios: true ios: true
image_path: "assets/icon.jpg" image_path: "assets/launcher.jpg"
min_sdk_android: 11 min_sdk_android: 21
# The "flutter_lints" package below contains a set of recommended lints to
# encourage good coding practices. The lint set provided by the package is
# activated in the `analysis_options.yaml` file located at the root of your
# package. See that file for information about deactivating specific lint
# rules and activating additional ones.
# flutter_lints: ^4.0.0
# For information on the generic Dart part of this file, see the # For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec # following page: https://dart.dev/tools/pub/pubspec
@ -76,8 +85,12 @@ flutter:
# The following line ensures that the Material Icons font is # The following line ensures that the Material Icons font is
# included with your application, so that you can use the icons in # included with your application, so that you can use the icons in
# the material Icons class. # the material Icons class.
generate: true
uses-material-design: true uses-material-design: true
assets:
- assets/svg/
# To add assets to your application, add an assets section, like this: # To add assets to your application, add an assets section, like this:
# assets: # assets:
# - images/a_dot_burr.jpeg # - images/a_dot_burr.jpeg
@ -107,7 +120,4 @@ flutter:
# weight: 700 # weight: 700
# #
# For details regarding fonts from package dependencies, # For details regarding fonts from package dependencies,
# see https://flutter.dev/to/font-from-package # see https://flutter.dev/to/font-from-package
generate: true
assets:
- assets/svg/