my diets have been update

This commit is contained in:
Username1548
2025-02-17 14:40:31 +07:00
parent 070d7e1047
commit 291947bd32
98 changed files with 4969 additions and 2670 deletions

View File

@@ -1,23 +1,46 @@
import 'dart:async';
import 'package:easy_debounce/easy_debounce.dart';
import 'package:eatvio_app/core/utils/toasts.dart';
import 'package:eatvio_app/features/diets/repositories/diet_repository.dart';
import 'package:eatvio_app/features/feed/presentation/bloc/recipes_cubit/recipes_state.dart';
import 'package:eatvio_app/features/feed/repositories/feed_repository.dart';
import 'package:eatvio_app/features/recipes/models/recipe_tag_model.dart';
import 'package:eatvio_app/features/recipes/reporitories/recipe_repository.dart';
import 'package:eatvio_app/features/create_recipe/models/recipe_tag_model.dart';
import 'package:eatvio_app/features/create_recipe/reporitories/recipe_repository.dart';
import 'package:eatvio_app/features/recipe/repositories/about_recipe_repository.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'dart:developer';
import 'package:go_router/go_router.dart';
class RecipesCubit extends Cubit<RecipesState> {
final FeedRepository feedRepository;
final RecipeRepository recipeRepository;
final AboutRecipeRepository aboutRecipeRepository;
Set<int> _selectedTags = {};
int currentPage = 1;
late int lastPage;
bool isLoading = false;
String? _query;
late final StreamSubscription likesStateSubscription;
late final StreamSubscription favoriteStateSubscription;
late final StreamSubscription commentsStateSubscription;
RecipesCubit({
required this.feedRepository,
required this.recipeRepository,
}) : super(const RecipesState.loading());
required this.aboutRecipeRepository,
}) : super(RecipesState.initial()) {
likesStateSubscription = aboutRecipeRepository.recipeLikeState.listen((likesState) {
_changeRecipeLikeState(likesState);
});
favoriteStateSubscription = aboutRecipeRepository.recipeFavoriteState.listen((favoriteState) {
_changeRecipeFavoriteState(favoriteState);
});
commentsStateSubscription = aboutRecipeRepository.recipeCommentsState.listen((commentsState) {
_changeRecipeCommentsState(commentsState);
});
}
loadRecipesList({
String? query,
@@ -28,9 +51,10 @@ class RecipesCubit extends Cubit<RecipesState> {
tags: _selectedTags.toList(),
query: query,
);
final recipesTags = (await recipeRepository.getRecipesTags());
emit(
RecipesState.loaded(
state.copyWith(
recipesList: recipesList,
recipesTags: recipesTags,
selectedTags: _selectedTags,
@@ -41,7 +65,7 @@ class RecipesCubit extends Cubit<RecipesState> {
lastPage = currentPage;
} catch (e, st) {
log(e.toString(), stackTrace: st);
emit(RecipesState.error(errorMessage: e.toString()));
emit(state.copyWith(errorMessage: e.toString()));
}
}
@@ -49,7 +73,7 @@ class RecipesCubit extends Cubit<RecipesState> {
if (currentPage < lastPage && !isLoading) {
isLoading = true;
emit((state as RecipesStateLoaded).copyWith(isLoading: isLoading));
emit(state.copyWith(isLoading: isLoading));
try {
if (currentPage < lastPage) {
@@ -61,9 +85,9 @@ class RecipesCubit extends Cubit<RecipesState> {
);
isLoading = false;
emit(
(state as RecipesStateLoaded).copyWith(
state.copyWith(
recipesList: [
...(state as RecipesStateLoaded).recipesList,
...state.recipesList,
...recipesList,
],
isLoading: isLoading,
@@ -72,7 +96,7 @@ class RecipesCubit extends Cubit<RecipesState> {
}
lastPage = currentPage;
} catch (e) {
emit(RecipesState.error(errorMessage: e.toString()));
emit(state.copyWith(errorMessage: e.toString()));
}
}
}
@@ -80,14 +104,202 @@ class RecipesCubit extends Cubit<RecipesState> {
updateTags(RecipeTag tag) {
_selectedTags.contains(tag.id) ? _selectedTags.remove(tag.id) : _selectedTags.add(tag.id);
emit(
(state as RecipesStateLoaded).copyWith(
state.copyWith(
selectedTags: _selectedTags,
selectedTagsCounter: _selectedTags.length,
),
);
}
likeRecipe(String slug) async => await feedRepository.likeRecipe(slug: slug);
Future<void> addRecipeToFavorite(String slug, int index) async {
final currentRecipes = state.recipesList;
final recipesForModification = [...currentRecipes];
final currentRecipe = currentRecipes[index];
unlikeRecipe(String slug) async => await feedRepository.unlikeRecipe(slug: slug);
recipesForModification[index] = currentRecipe.copyWith(
isFavorite: true,
);
emit(
state.copyWith(
recipesList: [
...recipesForModification,
],
isLoading: isLoading,
errorMessage: null,
),
);
EasyDebounce.debounce(
'add_or_remove_plan_from_favorite',
Duration(milliseconds: 200),
() async {
try {
await aboutRecipeRepository.addToFavorite(slug);
} catch (e) {
log(e.toString());
showErrorToast('Произошла ошибка. Попробуйте ещё раз через некоторое время');
emit(
state.copyWith(
recipesList: [
...currentRecipes,
],
isLoading: isLoading,
errorMessage: null,
),
);
}
},
);
}
Future<void> removeRecipeFromFavorite(String slug, int index) async {
final currentRecipes = state.recipesList;
final recipesForModification = [...currentRecipes];
final currentRecipe = currentRecipes[index];
recipesForModification[index] = currentRecipe.copyWith(
isFavorite: false,
);
emit(
state.copyWith(
recipesList: [
...recipesForModification,
],
isLoading: isLoading,
errorMessage: null,
),
);
EasyDebounce.debounce(
'add_or_remove_plan_from_favorite',
Duration(milliseconds: 200),
() async {
try {
await aboutRecipeRepository.removeFromFavorite(slug);
} catch (e) {
log(e.toString());
showErrorToast('Произошла ошибка. Попробуйте ещё раз через некоторое время');
emit(
state.copyWith(
recipesList: [
...currentRecipes,
],
isLoading: isLoading,
errorMessage: null,
),
);
}
},
);
}
Future<void> likeRecipe(String slug, int index) async {
final currentRecipes = state.recipesList;
final recipesForModification = [...currentRecipes];
final currentRecipe = currentRecipes[index];
if (currentRecipe.wasLikedByMe) {
recipesForModification[index] = currentRecipe.copyWith(
likesCount: currentRecipe.likesCount - 1,
wasLikedByMe: false,
);
emit(
state.copyWith(
recipesList: [
...recipesForModification,
],
isLoading: isLoading,
errorMessage: null,
),
);
} else {
recipesForModification[index] = currentRecipe.copyWith(
likesCount: currentRecipe.likesCount + 1,
wasLikedByMe: true,
);
emit(
state.copyWith(
recipesList: [
...recipesForModification,
],
isLoading: isLoading,
errorMessage: null,
),
);
}
EasyDebounce.debounce(
'like_plan',
Duration(milliseconds: 200),
() async {
try {
await aboutRecipeRepository.likeRecipe(slug);
} catch (e) {
log(e.toString());
emit(
state.copyWith(
recipesList: [
...currentRecipes,
],
isLoading: isLoading,
),
);
}
},
);
}
void _changeRecipeLikeState(LikesState likesState) {
final currentRecipes = state.recipesList;
final recipesForModification = [...currentRecipes];
final currentRecipe = currentRecipes[likesState.index];
recipesForModification[likesState.index] = currentRecipe.copyWith(
likesCount: likesState.totalLikes,
wasLikedByMe: likesState.wasLikedByMe,
);
emit(
state.copyWith(
recipesList: [
...recipesForModification,
],
isLoading: isLoading,
errorMessage: null,
),
);
}
void _changeRecipeFavoriteState(FavoriteState favoriteState) {
final currentRecipes = state.recipesList;
final recipesForModification = [...currentRecipes];
final currentRecipe = currentRecipes[favoriteState.index];
recipesForModification[favoriteState.index] = currentRecipe.copyWith(
isFavorite: favoriteState.isFavorite,
);
emit(
state.copyWith(
recipesList: [
...recipesForModification,
],
isLoading: isLoading,
errorMessage: null,
),
);
}
void _changeRecipeCommentsState(CommentsState commentsState) {
final currentRecipes = state.recipesList;
final recipesForModification = [...currentRecipes];
final currentRecipe = currentRecipes[commentsState.index];
recipesForModification[commentsState.index] = currentRecipe.copyWith(
commentsCount: commentsState.totalComments,
);
emit(
state.copyWith(
recipesList: [
...recipesForModification,
],
isLoading: isLoading,
errorMessage: null,
),
);
}
}

View File

@@ -1,24 +1,26 @@
import 'package:eatvio_app/features/feed/models/recipes_model.dart';
import 'package:eatvio_app/features/recipes/models/recipe_tag_model.dart';
import 'package:eatvio_app/features/create_recipe/models/recipe_tag_model.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
part 'recipes_state.freezed.dart';
@freezed
abstract class RecipesState with _$RecipesState {
const factory RecipesState() = _RecipesState;
const factory RecipesState.loading() = RecipesStateLoading;
const factory RecipesState.loaded({
required List<Recipes> recipesList,
const factory RecipesState({
required List<Recipe> recipesList,
required List<RecipeTag> recipesTags,
required Set<int> selectedTags,
required int selectedTagsCounter,
required bool isLoading,
}) = RecipesStateLoaded;
String? errorMessage,
}) = _RecipesState;
const factory RecipesState.error({
required String errorMessage,
}) = RecipesStateError;
factory RecipesState.initial() => RecipesState(
recipesList: [],
recipesTags: [],
selectedTags: {},
selectedTagsCounter: 0,
isLoading: true,
errorMessage: null,
);
}

View File

@@ -16,65 +16,17 @@ final _privateConstructorUsedError = UnsupportedError(
/// @nodoc
mixin _$RecipesState {
@optionalTypeArgs
TResult when<TResult extends Object?>(
TResult Function() $default, {
required TResult Function() loading,
required TResult Function(
List<Recipes> recipesList,
List<RecipeTag> recipesTags,
Set<int> selectedTags,
int selectedTagsCounter,
bool isLoading)
loaded,
required TResult Function(String errorMessage) error,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
TResult? Function()? $default, {
TResult? Function()? loading,
TResult? Function(List<Recipes> recipesList, List<RecipeTag> recipesTags,
Set<int> selectedTags, int selectedTagsCounter, bool isLoading)?
loaded,
TResult? Function(String errorMessage)? error,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>(
TResult Function()? $default, {
TResult Function()? loading,
TResult Function(List<Recipes> recipesList, List<RecipeTag> recipesTags,
Set<int> selectedTags, int selectedTagsCounter, bool isLoading)?
loaded,
TResult Function(String errorMessage)? error,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>(
TResult Function(_RecipesState value) $default, {
required TResult Function(RecipesStateLoading value) loading,
required TResult Function(RecipesStateLoaded value) loaded,
required TResult Function(RecipesStateError value) error,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>(
TResult? Function(_RecipesState value)? $default, {
TResult? Function(RecipesStateLoading value)? loading,
TResult? Function(RecipesStateLoaded value)? loaded,
TResult? Function(RecipesStateError value)? error,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>(
TResult Function(_RecipesState value)? $default, {
TResult Function(RecipesStateLoading value)? loading,
TResult Function(RecipesStateLoaded value)? loaded,
TResult Function(RecipesStateError value)? error,
required TResult orElse(),
}) =>
List<Recipe> get recipesList => throw _privateConstructorUsedError;
List<RecipeTag> get recipesTags => throw _privateConstructorUsedError;
Set<int> get selectedTags => throw _privateConstructorUsedError;
int get selectedTagsCounter => throw _privateConstructorUsedError;
bool get isLoading => throw _privateConstructorUsedError;
String? get errorMessage => throw _privateConstructorUsedError;
/// Create a copy of RecipesState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$RecipesStateCopyWith<RecipesState> get copyWith =>
throw _privateConstructorUsedError;
}
@@ -83,6 +35,14 @@ abstract class $RecipesStateCopyWith<$Res> {
factory $RecipesStateCopyWith(
RecipesState value, $Res Function(RecipesState) then) =
_$RecipesStateCopyWithImpl<$Res, RecipesState>;
@useResult
$Res call(
{List<Recipe> recipesList,
List<RecipeTag> recipesTags,
Set<int> selectedTags,
int selectedTagsCounter,
bool isLoading,
String? errorMessage});
}
/// @nodoc
@@ -97,13 +57,60 @@ class _$RecipesStateCopyWithImpl<$Res, $Val extends RecipesState>
/// Create a copy of RecipesState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? recipesList = null,
Object? recipesTags = null,
Object? selectedTags = null,
Object? selectedTagsCounter = null,
Object? isLoading = null,
Object? errorMessage = freezed,
}) {
return _then(_value.copyWith(
recipesList: null == recipesList
? _value.recipesList
: recipesList // ignore: cast_nullable_to_non_nullable
as List<Recipe>,
recipesTags: null == recipesTags
? _value.recipesTags
: recipesTags // ignore: cast_nullable_to_non_nullable
as List<RecipeTag>,
selectedTags: null == selectedTags
? _value.selectedTags
: selectedTags // ignore: cast_nullable_to_non_nullable
as Set<int>,
selectedTagsCounter: null == selectedTagsCounter
? _value.selectedTagsCounter
: selectedTagsCounter // ignore: cast_nullable_to_non_nullable
as int,
isLoading: null == isLoading
? _value.isLoading
: isLoading // ignore: cast_nullable_to_non_nullable
as bool,
errorMessage: freezed == errorMessage
? _value.errorMessage
: errorMessage // ignore: cast_nullable_to_non_nullable
as String?,
) as $Val);
}
}
/// @nodoc
abstract class _$$RecipesStateImplCopyWith<$Res> {
abstract class _$$RecipesStateImplCopyWith<$Res>
implements $RecipesStateCopyWith<$Res> {
factory _$$RecipesStateImplCopyWith(
_$RecipesStateImpl value, $Res Function(_$RecipesStateImpl) then) =
__$$RecipesStateImplCopyWithImpl<$Res>;
@override
@useResult
$Res call(
{List<Recipe> recipesList,
List<RecipeTag> recipesTags,
Set<int> selectedTags,
int selectedTagsCounter,
bool isLoading,
String? errorMessage});
}
/// @nodoc
@@ -116,268 +123,6 @@ class __$$RecipesStateImplCopyWithImpl<$Res>
/// Create a copy of RecipesState
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
class _$RecipesStateImpl implements _RecipesState {
const _$RecipesStateImpl();
@override
String toString() {
return 'RecipesState()';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType && other is _$RecipesStateImpl);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>(
TResult Function() $default, {
required TResult Function() loading,
required TResult Function(
List<Recipes> recipesList,
List<RecipeTag> recipesTags,
Set<int> selectedTags,
int selectedTagsCounter,
bool isLoading)
loaded,
required TResult Function(String errorMessage) error,
}) {
return $default();
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
TResult? Function()? $default, {
TResult? Function()? loading,
TResult? Function(List<Recipes> recipesList, List<RecipeTag> recipesTags,
Set<int> selectedTags, int selectedTagsCounter, bool isLoading)?
loaded,
TResult? Function(String errorMessage)? error,
}) {
return $default?.call();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>(
TResult Function()? $default, {
TResult Function()? loading,
TResult Function(List<Recipes> recipesList, List<RecipeTag> recipesTags,
Set<int> selectedTags, int selectedTagsCounter, bool isLoading)?
loaded,
TResult Function(String errorMessage)? error,
required TResult orElse(),
}) {
if ($default != null) {
return $default();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>(
TResult Function(_RecipesState value) $default, {
required TResult Function(RecipesStateLoading value) loading,
required TResult Function(RecipesStateLoaded value) loaded,
required TResult Function(RecipesStateError value) error,
}) {
return $default(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>(
TResult? Function(_RecipesState value)? $default, {
TResult? Function(RecipesStateLoading value)? loading,
TResult? Function(RecipesStateLoaded value)? loaded,
TResult? Function(RecipesStateError value)? error,
}) {
return $default?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>(
TResult Function(_RecipesState value)? $default, {
TResult Function(RecipesStateLoading value)? loading,
TResult Function(RecipesStateLoaded value)? loaded,
TResult Function(RecipesStateError value)? error,
required TResult orElse(),
}) {
if ($default != null) {
return $default(this);
}
return orElse();
}
}
abstract class _RecipesState implements RecipesState {
const factory _RecipesState() = _$RecipesStateImpl;
}
/// @nodoc
abstract class _$$RecipesStateLoadingImplCopyWith<$Res> {
factory _$$RecipesStateLoadingImplCopyWith(_$RecipesStateLoadingImpl value,
$Res Function(_$RecipesStateLoadingImpl) then) =
__$$RecipesStateLoadingImplCopyWithImpl<$Res>;
}
/// @nodoc
class __$$RecipesStateLoadingImplCopyWithImpl<$Res>
extends _$RecipesStateCopyWithImpl<$Res, _$RecipesStateLoadingImpl>
implements _$$RecipesStateLoadingImplCopyWith<$Res> {
__$$RecipesStateLoadingImplCopyWithImpl(_$RecipesStateLoadingImpl _value,
$Res Function(_$RecipesStateLoadingImpl) _then)
: super(_value, _then);
/// Create a copy of RecipesState
/// with the given fields replaced by the non-null parameter values.
}
/// @nodoc
class _$RecipesStateLoadingImpl implements RecipesStateLoading {
const _$RecipesStateLoadingImpl();
@override
String toString() {
return 'RecipesState.loading()';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$RecipesStateLoadingImpl);
}
@override
int get hashCode => runtimeType.hashCode;
@override
@optionalTypeArgs
TResult when<TResult extends Object?>(
TResult Function() $default, {
required TResult Function() loading,
required TResult Function(
List<Recipes> recipesList,
List<RecipeTag> recipesTags,
Set<int> selectedTags,
int selectedTagsCounter,
bool isLoading)
loaded,
required TResult Function(String errorMessage) error,
}) {
return loading();
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
TResult? Function()? $default, {
TResult? Function()? loading,
TResult? Function(List<Recipes> recipesList, List<RecipeTag> recipesTags,
Set<int> selectedTags, int selectedTagsCounter, bool isLoading)?
loaded,
TResult? Function(String errorMessage)? error,
}) {
return loading?.call();
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>(
TResult Function()? $default, {
TResult Function()? loading,
TResult Function(List<Recipes> recipesList, List<RecipeTag> recipesTags,
Set<int> selectedTags, int selectedTagsCounter, bool isLoading)?
loaded,
TResult Function(String errorMessage)? error,
required TResult orElse(),
}) {
if (loading != null) {
return loading();
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>(
TResult Function(_RecipesState value) $default, {
required TResult Function(RecipesStateLoading value) loading,
required TResult Function(RecipesStateLoaded value) loaded,
required TResult Function(RecipesStateError value) error,
}) {
return loading(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>(
TResult? Function(_RecipesState value)? $default, {
TResult? Function(RecipesStateLoading value)? loading,
TResult? Function(RecipesStateLoaded value)? loaded,
TResult? Function(RecipesStateError value)? error,
}) {
return loading?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>(
TResult Function(_RecipesState value)? $default, {
TResult Function(RecipesStateLoading value)? loading,
TResult Function(RecipesStateLoaded value)? loaded,
TResult Function(RecipesStateError value)? error,
required TResult orElse(),
}) {
if (loading != null) {
return loading(this);
}
return orElse();
}
}
abstract class RecipesStateLoading implements RecipesState {
const factory RecipesStateLoading() = _$RecipesStateLoadingImpl;
}
/// @nodoc
abstract class _$$RecipesStateLoadedImplCopyWith<$Res> {
factory _$$RecipesStateLoadedImplCopyWith(_$RecipesStateLoadedImpl value,
$Res Function(_$RecipesStateLoadedImpl) then) =
__$$RecipesStateLoadedImplCopyWithImpl<$Res>;
@useResult
$Res call(
{List<Recipes> recipesList,
List<RecipeTag> recipesTags,
Set<int> selectedTags,
int selectedTagsCounter,
bool isLoading});
}
/// @nodoc
class __$$RecipesStateLoadedImplCopyWithImpl<$Res>
extends _$RecipesStateCopyWithImpl<$Res, _$RecipesStateLoadedImpl>
implements _$$RecipesStateLoadedImplCopyWith<$Res> {
__$$RecipesStateLoadedImplCopyWithImpl(_$RecipesStateLoadedImpl _value,
$Res Function(_$RecipesStateLoadedImpl) _then)
: super(_value, _then);
/// Create a copy of RecipesState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
@@ -386,12 +131,13 @@ class __$$RecipesStateLoadedImplCopyWithImpl<$Res>
Object? selectedTags = null,
Object? selectedTagsCounter = null,
Object? isLoading = null,
Object? errorMessage = freezed,
}) {
return _then(_$RecipesStateLoadedImpl(
return _then(_$RecipesStateImpl(
recipesList: null == recipesList
? _value._recipesList
: recipesList // ignore: cast_nullable_to_non_nullable
as List<Recipes>,
as List<Recipe>,
recipesTags: null == recipesTags
? _value._recipesTags
: recipesTags // ignore: cast_nullable_to_non_nullable
@@ -408,26 +154,31 @@ class __$$RecipesStateLoadedImplCopyWithImpl<$Res>
? _value.isLoading
: isLoading // ignore: cast_nullable_to_non_nullable
as bool,
errorMessage: freezed == errorMessage
? _value.errorMessage
: errorMessage // ignore: cast_nullable_to_non_nullable
as String?,
));
}
}
/// @nodoc
class _$RecipesStateLoadedImpl implements RecipesStateLoaded {
const _$RecipesStateLoadedImpl(
{required final List<Recipes> recipesList,
class _$RecipesStateImpl implements _RecipesState {
const _$RecipesStateImpl(
{required final List<Recipe> recipesList,
required final List<RecipeTag> recipesTags,
required final Set<int> selectedTags,
required this.selectedTagsCounter,
required this.isLoading})
required this.isLoading,
this.errorMessage})
: _recipesList = recipesList,
_recipesTags = recipesTags,
_selectedTags = selectedTags;
final List<Recipes> _recipesList;
final List<Recipe> _recipesList;
@override
List<Recipes> get recipesList {
List<Recipe> get recipesList {
if (_recipesList is EqualUnmodifiableListView) return _recipesList;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(_recipesList);
@@ -453,17 +204,19 @@ class _$RecipesStateLoadedImpl implements RecipesStateLoaded {
final int selectedTagsCounter;
@override
final bool isLoading;
@override
final String? errorMessage;
@override
String toString() {
return 'RecipesState.loaded(recipesList: $recipesList, recipesTags: $recipesTags, selectedTags: $selectedTags, selectedTagsCounter: $selectedTagsCounter, isLoading: $isLoading)';
return 'RecipesState(recipesList: $recipesList, recipesTags: $recipesTags, selectedTags: $selectedTags, selectedTagsCounter: $selectedTagsCounter, isLoading: $isLoading, errorMessage: $errorMessage)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$RecipesStateLoadedImpl &&
other is _$RecipesStateImpl &&
const DeepCollectionEquality()
.equals(other._recipesList, _recipesList) &&
const DeepCollectionEquality()
@@ -473,7 +226,9 @@ class _$RecipesStateLoadedImpl implements RecipesStateLoaded {
(identical(other.selectedTagsCounter, selectedTagsCounter) ||
other.selectedTagsCounter == selectedTagsCounter) &&
(identical(other.isLoading, isLoading) ||
other.isLoading == isLoading));
other.isLoading == isLoading) &&
(identical(other.errorMessage, errorMessage) ||
other.errorMessage == errorMessage));
}
@override
@@ -483,287 +238,44 @@ class _$RecipesStateLoadedImpl implements RecipesStateLoaded {
const DeepCollectionEquality().hash(_recipesTags),
const DeepCollectionEquality().hash(_selectedTags),
selectedTagsCounter,
isLoading);
isLoading,
errorMessage);
/// Create a copy of RecipesState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$RecipesStateLoadedImplCopyWith<_$RecipesStateLoadedImpl> get copyWith =>
__$$RecipesStateLoadedImplCopyWithImpl<_$RecipesStateLoadedImpl>(
this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>(
TResult Function() $default, {
required TResult Function() loading,
required TResult Function(
List<Recipes> recipesList,
List<RecipeTag> recipesTags,
Set<int> selectedTags,
int selectedTagsCounter,
bool isLoading)
loaded,
required TResult Function(String errorMessage) error,
}) {
return loaded(
recipesList, recipesTags, selectedTags, selectedTagsCounter, isLoading);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
TResult? Function()? $default, {
TResult? Function()? loading,
TResult? Function(List<Recipes> recipesList, List<RecipeTag> recipesTags,
Set<int> selectedTags, int selectedTagsCounter, bool isLoading)?
loaded,
TResult? Function(String errorMessage)? error,
}) {
return loaded?.call(
recipesList, recipesTags, selectedTags, selectedTagsCounter, isLoading);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>(
TResult Function()? $default, {
TResult Function()? loading,
TResult Function(List<Recipes> recipesList, List<RecipeTag> recipesTags,
Set<int> selectedTags, int selectedTagsCounter, bool isLoading)?
loaded,
TResult Function(String errorMessage)? error,
required TResult orElse(),
}) {
if (loaded != null) {
return loaded(recipesList, recipesTags, selectedTags, selectedTagsCounter,
isLoading);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>(
TResult Function(_RecipesState value) $default, {
required TResult Function(RecipesStateLoading value) loading,
required TResult Function(RecipesStateLoaded value) loaded,
required TResult Function(RecipesStateError value) error,
}) {
return loaded(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>(
TResult? Function(_RecipesState value)? $default, {
TResult? Function(RecipesStateLoading value)? loading,
TResult? Function(RecipesStateLoaded value)? loaded,
TResult? Function(RecipesStateError value)? error,
}) {
return loaded?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>(
TResult Function(_RecipesState value)? $default, {
TResult Function(RecipesStateLoading value)? loading,
TResult Function(RecipesStateLoaded value)? loaded,
TResult Function(RecipesStateError value)? error,
required TResult orElse(),
}) {
if (loaded != null) {
return loaded(this);
}
return orElse();
}
_$$RecipesStateImplCopyWith<_$RecipesStateImpl> get copyWith =>
__$$RecipesStateImplCopyWithImpl<_$RecipesStateImpl>(this, _$identity);
}
abstract class RecipesStateLoaded implements RecipesState {
const factory RecipesStateLoaded(
{required final List<Recipes> recipesList,
abstract class _RecipesState implements RecipesState {
const factory _RecipesState(
{required final List<Recipe> recipesList,
required final List<RecipeTag> recipesTags,
required final Set<int> selectedTags,
required final int selectedTagsCounter,
required final bool isLoading}) = _$RecipesStateLoadedImpl;
required final bool isLoading,
final String? errorMessage}) = _$RecipesStateImpl;
List<Recipes> get recipesList;
@override
List<Recipe> get recipesList;
@override
List<RecipeTag> get recipesTags;
@override
Set<int> get selectedTags;
@override
int get selectedTagsCounter;
@override
bool get isLoading;
@override
String? get errorMessage;
/// Create a copy of RecipesState
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$RecipesStateLoadedImplCopyWith<_$RecipesStateLoadedImpl> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class _$$RecipesStateErrorImplCopyWith<$Res> {
factory _$$RecipesStateErrorImplCopyWith(_$RecipesStateErrorImpl value,
$Res Function(_$RecipesStateErrorImpl) then) =
__$$RecipesStateErrorImplCopyWithImpl<$Res>;
@useResult
$Res call({String errorMessage});
}
/// @nodoc
class __$$RecipesStateErrorImplCopyWithImpl<$Res>
extends _$RecipesStateCopyWithImpl<$Res, _$RecipesStateErrorImpl>
implements _$$RecipesStateErrorImplCopyWith<$Res> {
__$$RecipesStateErrorImplCopyWithImpl(_$RecipesStateErrorImpl _value,
$Res Function(_$RecipesStateErrorImpl) _then)
: super(_value, _then);
/// Create a copy of RecipesState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? errorMessage = null,
}) {
return _then(_$RecipesStateErrorImpl(
errorMessage: null == errorMessage
? _value.errorMessage
: errorMessage // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// @nodoc
class _$RecipesStateErrorImpl implements RecipesStateError {
const _$RecipesStateErrorImpl({required this.errorMessage});
@override
final String errorMessage;
@override
String toString() {
return 'RecipesState.error(errorMessage: $errorMessage)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$RecipesStateErrorImpl &&
(identical(other.errorMessage, errorMessage) ||
other.errorMessage == errorMessage));
}
@override
int get hashCode => Object.hash(runtimeType, errorMessage);
/// Create a copy of RecipesState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$RecipesStateErrorImplCopyWith<_$RecipesStateErrorImpl> get copyWith =>
__$$RecipesStateErrorImplCopyWithImpl<_$RecipesStateErrorImpl>(
this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>(
TResult Function() $default, {
required TResult Function() loading,
required TResult Function(
List<Recipes> recipesList,
List<RecipeTag> recipesTags,
Set<int> selectedTags,
int selectedTagsCounter,
bool isLoading)
loaded,
required TResult Function(String errorMessage) error,
}) {
return error(errorMessage);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>(
TResult? Function()? $default, {
TResult? Function()? loading,
TResult? Function(List<Recipes> recipesList, List<RecipeTag> recipesTags,
Set<int> selectedTags, int selectedTagsCounter, bool isLoading)?
loaded,
TResult? Function(String errorMessage)? error,
}) {
return error?.call(errorMessage);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>(
TResult Function()? $default, {
TResult Function()? loading,
TResult Function(List<Recipes> recipesList, List<RecipeTag> recipesTags,
Set<int> selectedTags, int selectedTagsCounter, bool isLoading)?
loaded,
TResult Function(String errorMessage)? error,
required TResult orElse(),
}) {
if (error != null) {
return error(errorMessage);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>(
TResult Function(_RecipesState value) $default, {
required TResult Function(RecipesStateLoading value) loading,
required TResult Function(RecipesStateLoaded value) loaded,
required TResult Function(RecipesStateError value) error,
}) {
return error(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>(
TResult? Function(_RecipesState value)? $default, {
TResult? Function(RecipesStateLoading value)? loading,
TResult? Function(RecipesStateLoaded value)? loaded,
TResult? Function(RecipesStateError value)? error,
}) {
return error?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>(
TResult Function(_RecipesState value)? $default, {
TResult Function(RecipesStateLoading value)? loading,
TResult Function(RecipesStateLoaded value)? loaded,
TResult Function(RecipesStateError value)? error,
required TResult orElse(),
}) {
if (error != null) {
return error(this);
}
return orElse();
}
}
abstract class RecipesStateError implements RecipesState {
const factory RecipesStateError({required final String errorMessage}) =
_$RecipesStateErrorImpl;
String get errorMessage;
/// Create a copy of RecipesState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
_$$RecipesStateErrorImplCopyWith<_$RecipesStateErrorImpl> get copyWith =>
_$$RecipesStateImplCopyWith<_$RecipesStateImpl> get copyWith =>
throw _privateConstructorUsedError;
}

View File

@@ -20,7 +20,7 @@ import 'package:eatvio_app/features/feed/presentation/widgets/tags_modal_widget.
import 'package:eatvio_app/features/feed/presentation/bloc/plans_cubit/plans_cubit.dart';
import 'package:eatvio_app/core/locator_service.dart';
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/features/recipes/presentation/pages/recipe_create_screen.dart';
import 'package:eatvio_app/features/create_recipe/presentation/pages/recipe_create_screen.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';

View File

@@ -1,5 +1,6 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:eatvio_app/core/const.dart';
import 'package:eatvio_app/core/utils/enums.dart';
import 'package:eatvio_app/core/widgets/bookmark_button.dart';
import 'package:eatvio_app/core/widgets/info_row.dart';
import 'package:eatvio_app/core/widgets/feed_icon_button.dart';
@@ -30,21 +31,27 @@ class DietsWidget extends StatefulWidget {
class _DietsWidgetState extends State<DietsWidget> {
@override
Widget build(BuildContext context) {
return DecoratedBox(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
color: Colors.white,
return InkWell(
onTap: () => GoRouter.of(context).pushNamed(
'aboutDietScreen',
extra: {
'diet': widget.diet,
'index': widget.index,
'navigateToComments': false,
},
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Stack(
children: [
InkWell(
onTap: () =>
GoRouter.of(context).pushNamed('aboutDietScreen', extra: {'diet': widget.diet, 'index': widget.index, 'navigateToComments': false}),
child: ClipRRect(
child: Ink(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
color: Colors.white,
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Stack(
children: [
ClipRRect(
borderRadius: BorderRadius.vertical(top: Radius.circular(12)),
child: CachedNetworkImage(
imageUrl: baseUrl + '/storage/' + widget.diet.image,
@@ -52,123 +59,124 @@ class _DietsWidgetState extends State<DietsWidget> {
width: MediaQuery.of(context).size.width,
),
),
),
Positioned(
right: 14,
child: BookmarkButton(
onTap: () async {
if (widget.diet.isFavorite) {
await context.read<DietsCubit>().removeDietFromFavorite(widget.diet.id, widget.index);
} else {
await context.read<DietsCubit>().addDietToFavorite(widget.diet.id, widget.index);
}
},
color: appTheme.whiteA700,
isFavorite: widget.diet.isFavorite,
borderRadius: BorderRadius.vertical(bottom: Radius.circular(12)),
width: 40,
height: 44,
size: 19,
),
),
Positioned(
bottom: 16,
child: SizedBox(
width: MediaQuery.sizeOf(context).width,
child: InfoRow(
diet: widget.diet,
itemsBackgroundColor: appTheme.whiteA700,
disableDescriptionOfTypes: true,
),
),
),
],
),
SizedBox(height: 12),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Text(
widget.diet.name,
style: TextStyles.textMSemibold.copyWith(color: appTheme.black),
),
),
if (widget.diet.details.isNotEmpty) ...[
SizedBox(
height: 12,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Html(
data: widget.diet.details.length > 200 ? widget.diet.details.substring(0, 200) + '...' : widget.diet.details,
style: {
"*": Style(
margin: Margins.zero,
color: appTheme.black,
fontSize: FontSize(TextStyles.textSMedium.fontSize ?? 14),
fontWeight: TextStyles.textSMedium.fontWeight ?? FontWeight.w400,
),
Positioned(
right: 14,
child: BookmarkButton(
onTap: () async {
if (widget.diet.isFavorite) {
await context.read<DietsCubit>().removeDietFromFavorite(widget.diet.id, widget.index);
} else {
await context.read<DietsCubit>().addDietToFavorite(widget.diet.id, widget.index);
}
},
color: appTheme.whiteA700,
isFavorite: widget.diet.isFavorite,
borderRadius: BorderRadius.vertical(bottom: Radius.circular(12)),
width: 40,
height: 44,
size: 19,
),
),
],
],
),
Padding(
padding: const EdgeInsets.only(left: 16, top: 12),
child: Row(
children: [
FeedIconButton(
icon: widget.diet.wasLikedByMe ? Icons.favorite_rounded : Icons.favorite_border_rounded,
text: widget.diet.totalLikes.toString(),
iconColor: widget.diet.wasLikedByMe ? appTheme.blueA400 : null,
backgroundColor: widget.diet.wasLikedByMe ? appTheme.transparentBlue : null,
onTap: () async {
await context.read<DietsCubit>().likeDiet(widget.diet.id, widget.index);
},
),
SizedBox(
width: 12,
),
FeedIconButton(
icon: Icons.chat_bubble_outline,
text: widget.diet.totalComments.toString(),
onTap: () =>
GoRouter.of(context).pushNamed('aboutDietScreen', extra: {'diet': widget.diet, 'index': widget.index, 'navigateToComments': true}),
),
SizedBox(
width: 12,
),
FeedIconButton(
svgIcon: SvgPicture.asset('assets/icons/repost.svg'),
onTap: () async {
final box = context.findRenderObject() as RenderBox?;
final result = await Share.shareUri(
Uri.parse(
baseUrl + '/ru/diet/' + widget.diet.id.toString(),
),
sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size,
);
switch (result.status) {
case ShareResultStatus.success:
case ShareResultStatus.dismissed:
case ShareResultStatus.unavailable:
}
},
),
Spacer(),
FeedIconButton(
svgIcon: SvgPicture.asset('assets/icons/eye2.svg'),
text: widget.diet.totalViews.toString(),
backgroundColor: Colors.transparent,
Positioned(
bottom: 16,
child: SizedBox(
width: MediaQuery.sizeOf(context).width,
child: InfoRow(
diet: widget.diet,
itemsBackgroundColor: appTheme.whiteA700,
disableDescriptionOfTypes: true,
type: ProductType.diet
),
),
),
],
),
),
SizedBox(height: 12),
],
SizedBox(height: 12),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Text(
widget.diet.name,
style: TextStyles.textMSemibold.copyWith(color: appTheme.black),
),
),
if (widget.diet.details.isNotEmpty) ...[
SizedBox(
height: 12,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Html(
data: widget.diet.details.length > 200 ? widget.diet.details.substring(0, 200) + '...' : widget.diet.details,
style: {
"*": Style(
margin: Margins.zero,
color: appTheme.black,
fontSize: FontSize(TextStyles.textSMedium.fontSize ?? 14),
fontWeight: TextStyles.textSMedium.fontWeight ?? FontWeight.w400,
),
},
),
),
],
],
),
Padding(
padding: const EdgeInsets.only(left: 16, top: 12),
child: Row(
children: [
FeedIconButton(
icon: widget.diet.wasLikedByMe ? Icons.favorite_rounded : Icons.favorite_border_rounded,
text: widget.diet.totalLikes.toString(),
iconColor: widget.diet.wasLikedByMe ? appTheme.blueA400 : null,
backgroundColor: widget.diet.wasLikedByMe ? appTheme.transparentBlue : null,
onTap: () async {
await context.read<DietsCubit>().likeDiet(widget.diet.id, widget.index);
},
),
SizedBox(
width: 12,
),
FeedIconButton(
icon: Icons.chat_bubble_outline,
text: widget.diet.totalComments.toString(),
onTap: () =>
GoRouter.of(context).pushNamed('aboutDietScreen', extra: {'diet': widget.diet, 'index': widget.index, 'navigateToComments': true}),
),
SizedBox(
width: 12,
),
FeedIconButton(
svgIcon: SvgPicture.asset('assets/icons/repost.svg'),
onTap: () async {
final box = context.findRenderObject() as RenderBox?;
final result = await Share.shareUri(
Uri.parse(
baseUrl + '/ru/diet/' + widget.diet.id.toString(),
),
sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size,
);
switch (result.status) {
case ShareResultStatus.success:
case ShareResultStatus.dismissed:
case ShareResultStatus.unavailable:
}
},
),
Spacer(),
FeedIconButton(
svgIcon: SvgPicture.asset('assets/icons/eye2.svg'),
text: widget.diet.totalViews.toString(),
backgroundColor: Colors.transparent,
),
],
),
),
SizedBox(height: 12),
],
),
),
);
}

View File

@@ -1,5 +1,6 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:eatvio_app/core/const.dart';
import 'package:eatvio_app/core/utils/enums.dart';
import 'package:eatvio_app/core/widgets/bookmark_button.dart';
import 'package:eatvio_app/core/widgets/info_row.dart';
import 'package:eatvio_app/core/widgets/feed_icon_button.dart';
@@ -33,21 +34,27 @@ class _PlanWidgetState extends State<PlanWidget> {
@override
Widget build(BuildContext context) {
final s = S.of(context);
return DecoratedBox(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
color: Colors.white,
return InkWell(
onTap: () => GoRouter.of(context).pushNamed(
'aboutPlanScreen',
extra: {
'plan': widget.plan,
'index': widget.index,
'navigateToComments': false,
},
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Stack(
children: [
InkWell(
onTap: () =>
GoRouter.of(context).pushNamed('aboutPlanScreen', extra: {'plan': widget.plan, 'index': widget.index, 'navigateToComments': false}),
child: ClipRRect(
child: Ink(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
color: Colors.white,
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Stack(
children: [
ClipRRect(
borderRadius: BorderRadius.vertical(top: Radius.circular(12)),
child: CachedNetworkImage(
imageUrl: baseUrl + '/storage/' + widget.plan.image,
@@ -55,176 +62,177 @@ class _PlanWidgetState extends State<PlanWidget> {
width: MediaQuery.of(context).size.width,
),
),
),
Positioned(
right: 14,
child: BookmarkButton(
onTap: () async {
if (widget.plan.isFavorite) {
await context.read<PlansCubit>().removePlanFromFavorite(widget.plan.slug, widget.index);
} else {
await context.read<PlansCubit>().addPlanToFavorite(widget.plan.slug, widget.index);
}
},
color: appTheme.whiteA700,
isFavorite: widget.plan.isFavorite,
borderRadius: BorderRadius.vertical(bottom: Radius.circular(12)),
width: 40,
height: 44,
size: 19,
),
),
Positioned(
bottom: 16,
child: SizedBox(
width: MediaQuery.sizeOf(context).width,
child: InfoRow(
plan: widget.plan,
itemsBackgroundColor: appTheme.whiteA700,
disableDescriptionOfTypes: true,
Positioned(
right: 14,
child: BookmarkButton(
onTap: () async {
if (widget.plan.isFavorite) {
await context.read<PlansCubit>().removePlanFromFavorite(widget.plan.slug, widget.index);
} else {
await context.read<PlansCubit>().addPlanToFavorite(widget.plan.slug, widget.index);
}
},
color: appTheme.whiteA700,
isFavorite: widget.plan.isFavorite,
borderRadius: BorderRadius.vertical(bottom: Radius.circular(12)),
width: 40,
height: 44,
size: 19,
),
),
),
],
),
SizedBox(height: 12),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Text(
widget.plan.name,
style: TextStyles.textMSemibold.copyWith(color: appTheme.black),
),
),
if (widget.plan.details.isNotEmpty) ...[
SizedBox(
height: 12,
Positioned(
bottom: 16,
child: SizedBox(
width: MediaQuery.sizeOf(context).width,
child: InfoRow(
plan: widget.plan,
itemsBackgroundColor: appTheme.whiteA700,
disableDescriptionOfTypes: true,
type: ProductType.plan
),
),
),
],
),
SizedBox(height: 12),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Html(
data: widget.plan.details.length > 200 ? widget.plan.details.substring(0, 200) + '...' : widget.plan.details,
style: {
"*": Style(
margin: Margins.zero,
color: appTheme.black,
fontSize: FontSize(TextStyles.textSMedium.fontSize ?? 14),
fontWeight: TextStyles.textSMedium.fontWeight ?? FontWeight.w400,
),
child: Text(
widget.plan.name,
style: TextStyles.textMSemibold.copyWith(color: appTheme.black),
),
),
if (widget.plan.details.isNotEmpty) ...[
SizedBox(
height: 12,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Html(
data: widget.plan.details.length > 200 ? widget.plan.details.substring(0, 200) + '...' : widget.plan.details,
style: {
"*": Style(
margin: Margins.zero,
color: appTheme.black,
fontSize: FontSize(TextStyles.textSMedium.fontSize ?? 14),
fontWeight: TextStyles.textSMedium.fontWeight ?? FontWeight.w400,
),
},
),
),
],
],
),
SizedBox(height: 16),
Padding(
padding: const EdgeInsets.only(left: 16.0),
child: ListTile(
contentPadding: EdgeInsets.zero,
leading: Container(
width: 46,
height: 46,
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
image: NetworkImage(widget.plan.author.authorProfileIcon),
fit: BoxFit.cover,
),
),
),
subtitle: Row(
children: [
InfoBouble(
radius: 12,
backgroundColor: appTheme.gray50,
padding: EdgeInsets.symmetric(vertical: 4, horizontal: 10),
children: [
Text(
'${widget.plan.author.authorPlaceInRating}-й в рейтинге',
style: TextStyles.textXSSemibold.copyWith(
color: appTheme.blueA400,
),
),
],
),
Spacer(),
Text(
'${widget.plan.packetsCount == 1 ? widget.plan.packet1Options?.price : '${s.from} ${widget.plan.minPriceOfOptions.toStringAsFixed(0)}'}₽',
style: TextStyles.headingXLSemibold.copyWith(color: appTheme.greenA700),
),
SizedBox(width: 16),
],
),
title: Padding(
padding: const EdgeInsets.only(bottom: 4.0),
child: Text(
widget.plan.author.authorName,
style: TextStyles.textSSemibold.copyWith(
color: appTheme.black,
),
),
),
),
),
SizedBox(height: 16),
Padding(
padding: const EdgeInsets.only(
left: 16,
),
child: Row(
children: [
FeedIconButton(
icon: widget.plan.wasLikedByMe ? Icons.favorite_rounded : Icons.favorite_border_rounded,
text: widget.plan.totalLikes.toString(),
iconColor: widget.plan.wasLikedByMe ? appTheme.blueA400 : null,
backgroundColor: widget.plan.wasLikedByMe ? appTheme.transparentBlue : null,
onTap: () async {
await context.read<PlansCubit>().likePlan(widget.plan.slug, widget.index);
},
),
),
],
],
),
SizedBox(height: 16),
Padding(
padding: const EdgeInsets.only(left: 16.0),
child: ListTile(
contentPadding: EdgeInsets.zero,
leading: Container(
width: 46,
height: 46,
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
image: NetworkImage(widget.plan.author.authorProfileIcon),
fit: BoxFit.cover,
SizedBox(
width: 12,
),
),
),
subtitle: Row(
children: [
InfoBouble(
radius: 12,
backgroundColor: appTheme.gray50,
padding: EdgeInsets.symmetric(vertical: 4, horizontal: 10),
children: [
Text(
'${widget.plan.author.authorPlaceInRating}-й в рейтинге',
style: TextStyles.textXSSemibold.copyWith(
color: appTheme.blueA400,
FeedIconButton(
icon: Icons.chat_bubble_outline,
text: widget.plan.totalComments.toString(),
onTap: () =>
GoRouter.of(context).pushNamed('aboutPlanScreen', extra: {'plan': widget.plan, 'index': widget.index, 'navigateToComments': true}),
),
SizedBox(
width: 12,
),
FeedIconButton(
svgIcon: SvgPicture.asset('assets/icons/repost.svg'),
onTap: () async {
final box = context.findRenderObject() as RenderBox?;
final result = await Share.shareUri(
Uri.parse(
baseUrl + '/ru/diet/' + widget.plan.id.toString(),
),
),
],
sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size,
);
switch (result.status) {
case ShareResultStatus.success:
case ShareResultStatus.dismissed:
case ShareResultStatus.unavailable:
}
},
),
Spacer(),
Text(
'${widget.plan.packetsCount == 1 ? widget.plan.packet1Options?.price : '${s.from} ${widget.plan.minPriceOfOptions.toStringAsFixed(0)}'}₽',
style: TextStyles.headingXLSemibold.copyWith(color: appTheme.greenA700),
FeedIconButton(
svgIcon: SvgPicture.asset('assets/icons/eye2.svg'),
text: widget.plan.totalViews.toString(),
backgroundColor: Colors.transparent,
),
SizedBox(width: 16),
],
),
title: Padding(
padding: const EdgeInsets.only(bottom: 4.0),
child: Text(
widget.plan.author.authorName,
style: TextStyles.textSSemibold.copyWith(
color: appTheme.black,
),
),
),
),
),
SizedBox(height: 16),
Padding(
padding: const EdgeInsets.only(
left: 16,
),
child: Row(
children: [
FeedIconButton(
icon: widget.plan.wasLikedByMe ? Icons.favorite_rounded : Icons.favorite_border_rounded,
text: widget.plan.totalLikes.toString(),
iconColor: widget.plan.wasLikedByMe ? appTheme.blueA400 : null,
backgroundColor: widget.plan.wasLikedByMe ? appTheme.transparentBlue : null,
onTap: () async {
await context.read<PlansCubit>().likePlan(widget.plan.slug, widget.index);
},
),
SizedBox(
width: 12,
),
FeedIconButton(
icon: Icons.chat_bubble_outline,
text: widget.plan.totalComments.toString(),
onTap: () =>
GoRouter.of(context).pushNamed('aboutPlanScreen', extra: {'plan': widget.plan, 'index': widget.index, 'navigateToComments': true}),
),
SizedBox(
width: 12,
),
FeedIconButton(
svgIcon: SvgPicture.asset('assets/icons/repost.svg'),
onTap: () async {
final box = context.findRenderObject() as RenderBox?;
final result = await Share.shareUri(
Uri.parse(
baseUrl + '/ru/diet/' + widget.plan.id.toString(),
),
sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size,
);
switch (result.status) {
case ShareResultStatus.success:
case ShareResultStatus.dismissed:
case ShareResultStatus.unavailable:
}
},
),
Spacer(),
FeedIconButton(
svgIcon: SvgPicture.asset('assets/icons/eye2.svg'),
text: widget.plan.totalViews.toString(),
backgroundColor: Colors.transparent,
),
],
),
),
SizedBox(height: 12),
],
SizedBox(height: 12),
],
),
),
);
}

View File

@@ -14,38 +14,39 @@ class Recipes extends StatelessWidget {
onRefresh: () => context.read<RecipesCubit>().loadRecipesList(),
child: BlocBuilder<RecipesCubit, RecipesState>(
builder: (BuildContext context, RecipesState state) {
if (state is RecipesStateLoaded) {
return ListView.separated(
padding: EdgeInsets.symmetric(vertical: 8),
shrinkWrap: true,
physics: BouncingScrollPhysics(),
itemBuilder: (context, index) {
return RecipesWidget(
recipes: state.recipesList[index],
index: index,
);
},
separatorBuilder: (context, index) {
return SizedBox(height: 8);
},
itemCount: state.recipesList.length,
);
} else if (state is RecipesStateError) {
return Scaffold(
backgroundColor: Colors.grey.shade200,
body: Padding(
padding: const EdgeInsets.all(16),
child: Center(
child: Text(state.errorMessage),
),
),
);
} else {
if (state.isLoading) {
return Scaffold(
backgroundColor: Colors.grey.shade200,
body: const Loader(),
);
}
if (state.errorMessage != null) {
return Scaffold(
backgroundColor: Colors.grey.shade200,
body: Padding(
padding: const EdgeInsets.all(16),
child: Center(
child: Text(state.errorMessage ?? ''),
),
),
);
}
return ListView.separated(
padding: EdgeInsets.symmetric(vertical: 8),
shrinkWrap: true,
physics: BouncingScrollPhysics(),
itemBuilder: (context, index) {
return RecipesWidget(
recipe: state.recipesList[index],
index: index,
);
},
separatorBuilder: (context, index) {
return SizedBox(height: 8);
},
itemCount: state.recipesList.length,
);
},
),
);

View File

@@ -2,11 +2,15 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:eatvio_app/core/const.dart';
import 'package:eatvio_app/core/theme/custom_text_style.dart';
import 'package:eatvio_app/core/utils/localization_utils.dart';
import 'package:eatvio_app/core/widgets/bookmark_button.dart';
import 'package:eatvio_app/core/widgets/feed_icon_button.dart';
import 'package:eatvio_app/features/feed/models/recipes_model.dart';
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/features/feed/presentation/bloc/recipes_cubit/recipes_cubit.dart';
import 'package:eatvio_app/features/feed/presentation/bloc/recipes_cubit/recipes_state.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_html/flutter_html.dart';
@@ -16,11 +20,11 @@ import 'package:share_plus/share_plus.dart';
class RecipesWidget extends StatefulWidget {
final int index;
final Recipes recipes;
final Recipe recipe;
const RecipesWidget({
super.key,
required this.recipes,
required this.recipe,
required this.index,
});
@@ -29,177 +33,207 @@ class RecipesWidget extends StatefulWidget {
}
class _RecipesWidgetState extends State<RecipesWidget> {
late bool isLiked;
late int totalLikes;
@override
void initState() {
super.initState();
isLiked = false;
}
@override
Widget build(BuildContext context) {
final s = S.of(context);
return BlocBuilder<RecipesCubit, RecipesState>(
builder: (BuildContext context, RecipesState state) {
if (state is RecipesStateLoaded) {
isLiked = state.recipesList[widget.index].wasLikedByMe;
totalLikes = state.recipesList[widget.index].likesCount;
return InkWell(
borderRadius: BorderRadius.circular(12),
onTap: () => GoRouter.of(context).pushNamed('aboutRecipesScreen', extra: widget.recipes),
child: Ink(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
color: Colors.white,
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Stack(
children: [
ClipRRect(
borderRadius: BorderRadius.vertical(top: Radius.circular(12)),
child: CachedNetworkImage(
imageUrl: baseUrl + '/storage/' + widget.recipes.image,
fit: BoxFit.fitWidth,
width: MediaQuery.of(context).size.width,
),
),
Positioned(
left: 8,
bottom: 8,
child: Wrap(
runSpacing: 8,
children: [
_iconButton('assets/icons/clock.svg', widget.recipes.cookingTime.toString() + ' минут'),
SizedBox(width: 8),
_iconButton('assets/icons/steps.svg', '${widget.recipes.steps?.length.toString()}' + ' этапов'),
SizedBox(width: 8),
_iconButton('assets/icons/calories.svg', widget.recipes.calories.toStringAsFixed(0) + ' ккал'),
],
),
),
],
),
SizedBox(height: 12),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 12),
child: Text(
widget.recipes.title ?? '',
style: TextStyle(
fontWeight: FontWeight.w600,
color: Colors.black87,
final isLiked = widget.recipe.wasLikedByMe;
final totalLikes = widget.recipe.likesCount;
final isFavorite = widget.recipe.isFavorite;
final hours = widget.recipe.cookingTime ~/ 60;
final minutes = widget.recipe.cookingTime % 60;
final String timeTitle;
if (hours > 0) {
timeTitle = '$hours ${getHourForm(hours)} $minutes ${getMinuteForm(minutes)}';
} else {
timeTitle = '$minutes ${getMinuteForm(minutes)}';
}
return InkWell(
borderRadius: BorderRadius.circular(12),
onTap: () => GoRouter.of(context).pushNamed(
'aboutRecipesScreen',
extra: {
'recipe': widget.recipe,
'index': widget.index,
'navigateToComments': false,
},
),
child: Ink(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
color: Colors.white,
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Stack(
children: [
ClipRRect(
borderRadius: BorderRadius.vertical(top: Radius.circular(12)),
child: CachedNetworkImage(
imageUrl: baseUrl + '/storage/' + widget.recipe.image,
fit: BoxFit.fitWidth,
width: MediaQuery.of(context).size.width,
),
),
),
if (widget.recipes.description.isNotEmpty)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 4),
child: Html(
data: widget.recipes.description.length > 200 ? widget.recipes.description.substring(0, 200) : widget.recipes.description,
style: {
"*": Style(
color: Colors.black87,
),
Positioned(
left: 8,
bottom: 8,
child: Wrap(
runSpacing: 8,
children: [
_iconButton('assets/icons/clock.svg', timeTitle),
SizedBox(width: 8),
_iconButton('assets/icons/steps.svg', '${widget.recipe.steps?.length ?? 0} ${getStepForm(widget.recipe.steps?.length ?? 0)}'),
SizedBox(width: 8),
_iconButton('assets/icons/calories.svg', widget.recipe.calories.toStringAsFixed(0) + ' ккал'),
],
),
),
Positioned(
right: 14,
child: BookmarkButton(
onTap: () async {
if (isFavorite) {
await context.read<RecipesCubit>().removeRecipeFromFavorite(widget.recipe.slug, widget.index);
} else {
await context.read<RecipesCubit>().addRecipeToFavorite(widget.recipe.slug, widget.index);
}
},
color: appTheme.whiteA700,
isFavorite: isFavorite,
borderRadius: BorderRadius.vertical(bottom: Radius.circular(12)),
width: 40,
height: 44,
size: 19,
),
),
if (widget.recipes.description.length > 200)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Text(
'Читать полностью...',
style: TextStyle(
height: 1,
color: appTheme.blueA400,
decoration: TextDecoration.underline,
),
),
),
],
),
SizedBox(height: 12),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Text(
widget.recipe.title ?? '',
style: TextStyles.textMSemibold.copyWith(color: appTheme.black),
),
),
if (widget.recipe.videoUrl != null && widget.recipe.videoUrl!.isNotEmpty) ...[
SizedBox(height: 12),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 12),
padding: const EdgeInsets.only(left: 15),
child: Row(
children: [
FeedIconButton(
icon: isLiked ? Icons.favorite_rounded : Icons.favorite_border_rounded,
text: widget.recipes.likesCount.toString(),
iconColor: isLiked ? Colors.red.withValues(alpha: 0.8) : null,
backgroundColor: isLiked ? Colors.red.withValues(alpha: 0.1) : null,
textColor: isLiked ? Colors.red.withValues(alpha: 0.8) : null,
onTap: () async {
setState(() {
isLiked = !isLiked;
isLiked ? totalLikes++ : totalLikes--;
});
isLiked
? await context.read<RecipesCubit>().likeRecipe(state.recipesList[widget.index].slug)
: await context.read<RecipesCubit>().unlikeRecipe(state.recipesList[widget.index].slug);
await context.read<RecipesCubit>().loadRecipesList();
},
),
SvgPicture.asset('assets/icons/play_icon.svg', width: 16, height: 16),
SizedBox(width: 8),
FeedIconButton(
svgIcon: SvgPicture.asset(
'assets/icons/comment.svg',
height: 20,
width: 20,
colorFilter: ColorFilter.mode(
appTheme.gray600,
BlendMode.srcIn,
),
),
text: widget.recipes.commentsCount.toString(),
onTap: () => GoRouter.of(context).pushNamed(
'aboutRecipesScreen',
extra: widget.recipes,
),
),
SizedBox(width: 8),
FeedIconButton(
svgIcon: SvgPicture.asset(
height: 20,
width: 20,
'assets/icons/share.svg',
colorFilter: ColorFilter.mode(appTheme.gray600, BlendMode.srcIn),
),
onTap: () {
final box = context.findRenderObject() as RenderBox?;
Share.shareUri(
Uri.parse(
baseUrl + '/ru/blog_post/' + widget.recipes.id.toString(),
),
sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size,
);
},
),
Spacer(),
Icon(
Icons.visibility_rounded,
size: 16,
color: appTheme.gray500,
),
SizedBox(width: 4),
Text(
widget.recipes.viewsCount.toString(),
style: TextStyle(
fontSize: 12,
color: appTheme.gray500,
fontWeight: FontWeight.w400,
),
s.there_is_a_video,
style: TextStyles.textXSSemibold.copyWith(color: appTheme.black),
),
],
),
),
SizedBox(height: 12),
],
),
SizedBox(height: 12),
if (widget.recipe.description.isNotEmpty)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Html(
data: widget.recipe.description.length > 200 ? widget.recipe.description.substring(0, 200) : widget.recipe.description,
style: {
"*": Style(
color: appTheme.black,
margin: Margins.all(0),
fontFamily: TextStyles.textSMedium.fontFamily,
fontSize: FontSize(TextStyles.textSMedium.fontSize ?? 14),
fontWeight: TextStyles.textSMedium.fontWeight,
),
},
),
),
if (widget.recipe.description.length > 200)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Text(
'Читать полностью...',
style: TextStyle(
height: 1,
color: appTheme.blueA400,
decoration: TextDecoration.underline,
),
),
),
SizedBox(height: 12),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 12),
child: Row(
children: [
FeedIconButton(
icon: isLiked ? Icons.favorite_rounded : Icons.favorite_border_rounded,
text: totalLikes.toString(),
iconColor: isLiked ? Colors.red.withValues(alpha: 0.8) : null,
backgroundColor: isLiked ? Colors.red.withValues(alpha: 0.1) : null,
textColor: isLiked ? Colors.red.withValues(alpha: 0.8) : null,
onTap: () async {
await context.read<RecipesCubit>().likeRecipe(widget.recipe.slug, widget.index);
},
),
SizedBox(width: 8),
FeedIconButton(
icon: Icons.chat_bubble_outline,
text: widget.recipe.commentsCount.toString(),
onTap: () => GoRouter.of(context).pushNamed(
'aboutRecipesScreen',
extra: {
'recipe': widget.recipe,
'index': widget.index,
'navigateToComments': true,
},
),
),
SizedBox(width: 8),
FeedIconButton(
svgIcon: SvgPicture.asset(
height: 15,
width: 12,
'assets/icons/repost.svg',
colorFilter: ColorFilter.mode(appTheme.gray600, BlendMode.srcIn),
),
onTap: () {
final box = context.findRenderObject() as RenderBox?;
Share.shareUri(
Uri.parse(
baseUrl + '/ru/blog_post/' + widget.recipe.id.toString(),
),
sharePositionOrigin: box!.localToGlobal(Offset.zero) & box.size,
);
},
),
Spacer(),
Icon(
Icons.visibility_rounded,
size: 16,
color: appTheme.gray500,
),
SizedBox(width: 4),
Text(
widget.recipe.viewsCount.toString(),
style: TextStyle(
fontSize: 12,
color: appTheme.gray500,
fontWeight: FontWeight.w400,
),
),
],
),
),
SizedBox(height: 12),
],
),
);
}
return Container();
),
);
},
);
}
@@ -208,7 +242,7 @@ class _RecipesWidgetState extends State<RecipesWidget> {
return Container(
padding: EdgeInsets.symmetric(horizontal: 12, vertical: 4),
decoration: BoxDecoration(
color: Colors.white.withValues(alpha: 0.8),
color: appTheme.whiteA700,
borderRadius: BorderRadius.circular(16),
),
height: 32,

View File

@@ -1,6 +1,6 @@
import 'package:eatvio_app/features/feed/presentation/bloc/recipes_cubit/recipes_cubit.dart';
import 'package:eatvio_app/features/feed/presentation/bloc/recipes_cubit/recipes_state.dart';
import 'package:eatvio_app/features/recipes/models/recipe_tag_model.dart';
import 'package:eatvio_app/features/create_recipe/models/recipe_tag_model.dart';
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
@@ -23,25 +23,21 @@ class _TagsModalWidgetState extends State<TagsModalWidget> {
return BlocBuilder<RecipesCubit, RecipesState>(
bloc: widget.recipesCubit,
builder: (BuildContext context, RecipesState state) {
if (state is RecipesStateLoaded) {
return Container(
padding: EdgeInsets.all(16),
width: MediaQuery.of(context).size.width,
child: Wrap(
spacing: 8,
runSpacing: -8,
children: [
for (int i = 0; i < state.recipesTags.length; i++)
_tagChip(
tag: state.recipesTags[i],
isSelected: state.selectedTags.contains(state.recipesTags[i].id),
),
],
),
);
} else {
return Container();
}
return Container(
padding: EdgeInsets.all(16),
width: MediaQuery.of(context).size.width,
child: Wrap(
spacing: 8,
runSpacing: -8,
children: [
for (int i = 0; i < state.recipesTags.length; i++)
_tagChip(
tag: state.recipesTags[i],
isSelected: state.selectedTags.contains(state.recipesTags[i].id),
),
],
),
);
},
);
}