forked from eatvio/eatvio_app
feat(Лента): фильтрация рецептов по тегам, поиск по строке
This commit is contained in:
@@ -10,7 +10,7 @@ abstract class CommentsState with _$CommentsState {
|
||||
const factory CommentsState.loading() = CommentsStateLoading;
|
||||
|
||||
const factory CommentsState.loaded({
|
||||
required Comment comment,
|
||||
required CommentModel comment,
|
||||
}) = CommentsStateLoaded;
|
||||
|
||||
const factory CommentsState.error({
|
||||
|
||||
@@ -20,7 +20,7 @@ mixin _$CommentsState {
|
||||
TResult when<TResult extends Object?>(
|
||||
TResult Function() $default, {
|
||||
required TResult Function() loading,
|
||||
required TResult Function(Comment comment) loaded,
|
||||
required TResult Function(CommentModel comment) loaded,
|
||||
required TResult Function(String errorMessage) error,
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@@ -28,7 +28,7 @@ mixin _$CommentsState {
|
||||
TResult? whenOrNull<TResult extends Object?>(
|
||||
TResult? Function()? $default, {
|
||||
TResult? Function()? loading,
|
||||
TResult? Function(Comment comment)? loaded,
|
||||
TResult? Function(CommentModel comment)? loaded,
|
||||
TResult? Function(String errorMessage)? error,
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@@ -36,7 +36,7 @@ mixin _$CommentsState {
|
||||
TResult maybeWhen<TResult extends Object?>(
|
||||
TResult Function()? $default, {
|
||||
TResult Function()? loading,
|
||||
TResult Function(Comment comment)? loaded,
|
||||
TResult Function(CommentModel comment)? loaded,
|
||||
TResult Function(String errorMessage)? error,
|
||||
required TResult orElse(),
|
||||
}) =>
|
||||
@@ -126,7 +126,7 @@ class _$CommentsStateImpl implements _CommentsState {
|
||||
TResult when<TResult extends Object?>(
|
||||
TResult Function() $default, {
|
||||
required TResult Function() loading,
|
||||
required TResult Function(Comment comment) loaded,
|
||||
required TResult Function(CommentModel comment) loaded,
|
||||
required TResult Function(String errorMessage) error,
|
||||
}) {
|
||||
return $default();
|
||||
@@ -137,7 +137,7 @@ class _$CommentsStateImpl implements _CommentsState {
|
||||
TResult? whenOrNull<TResult extends Object?>(
|
||||
TResult? Function()? $default, {
|
||||
TResult? Function()? loading,
|
||||
TResult? Function(Comment comment)? loaded,
|
||||
TResult? Function(CommentModel comment)? loaded,
|
||||
TResult? Function(String errorMessage)? error,
|
||||
}) {
|
||||
return $default?.call();
|
||||
@@ -148,7 +148,7 @@ class _$CommentsStateImpl implements _CommentsState {
|
||||
TResult maybeWhen<TResult extends Object?>(
|
||||
TResult Function()? $default, {
|
||||
TResult Function()? loading,
|
||||
TResult Function(Comment comment)? loaded,
|
||||
TResult Function(CommentModel comment)? loaded,
|
||||
TResult Function(String errorMessage)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
@@ -241,7 +241,7 @@ class _$CommentsStateLoadingImpl implements CommentsStateLoading {
|
||||
TResult when<TResult extends Object?>(
|
||||
TResult Function() $default, {
|
||||
required TResult Function() loading,
|
||||
required TResult Function(Comment comment) loaded,
|
||||
required TResult Function(CommentModel comment) loaded,
|
||||
required TResult Function(String errorMessage) error,
|
||||
}) {
|
||||
return loading();
|
||||
@@ -252,7 +252,7 @@ class _$CommentsStateLoadingImpl implements CommentsStateLoading {
|
||||
TResult? whenOrNull<TResult extends Object?>(
|
||||
TResult? Function()? $default, {
|
||||
TResult? Function()? loading,
|
||||
TResult? Function(Comment comment)? loaded,
|
||||
TResult? Function(CommentModel comment)? loaded,
|
||||
TResult? Function(String errorMessage)? error,
|
||||
}) {
|
||||
return loading?.call();
|
||||
@@ -263,7 +263,7 @@ class _$CommentsStateLoadingImpl implements CommentsStateLoading {
|
||||
TResult maybeWhen<TResult extends Object?>(
|
||||
TResult Function()? $default, {
|
||||
TResult Function()? loading,
|
||||
TResult Function(Comment comment)? loaded,
|
||||
TResult Function(CommentModel comment)? loaded,
|
||||
TResult Function(String errorMessage)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
@@ -321,9 +321,9 @@ abstract class _$$CommentsStateLoadedImplCopyWith<$Res> {
|
||||
$Res Function(_$CommentsStateLoadedImpl) then) =
|
||||
__$$CommentsStateLoadedImplCopyWithImpl<$Res>;
|
||||
@useResult
|
||||
$Res call({Comment comment});
|
||||
$Res call({CommentModel comment});
|
||||
|
||||
$CommentCopyWith<$Res> get comment;
|
||||
$CommentModelCopyWith<$Res> get comment;
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@@ -343,14 +343,14 @@ class __$$CommentsStateLoadedImplCopyWithImpl<$Res>
|
||||
comment: null == comment
|
||||
? _value.comment
|
||||
: comment // ignore: cast_nullable_to_non_nullable
|
||||
as Comment,
|
||||
as CommentModel,
|
||||
));
|
||||
}
|
||||
|
||||
@override
|
||||
@pragma('vm:prefer-inline')
|
||||
$CommentCopyWith<$Res> get comment {
|
||||
return $CommentCopyWith<$Res>(_value.comment, (value) {
|
||||
$CommentModelCopyWith<$Res> get comment {
|
||||
return $CommentModelCopyWith<$Res>(_value.comment, (value) {
|
||||
return _then(_value.copyWith(comment: value));
|
||||
});
|
||||
}
|
||||
@@ -362,7 +362,7 @@ class _$CommentsStateLoadedImpl implements CommentsStateLoaded {
|
||||
const _$CommentsStateLoadedImpl({required this.comment});
|
||||
|
||||
@override
|
||||
final Comment comment;
|
||||
final CommentModel comment;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
@@ -392,7 +392,7 @@ class _$CommentsStateLoadedImpl implements CommentsStateLoaded {
|
||||
TResult when<TResult extends Object?>(
|
||||
TResult Function() $default, {
|
||||
required TResult Function() loading,
|
||||
required TResult Function(Comment comment) loaded,
|
||||
required TResult Function(CommentModel comment) loaded,
|
||||
required TResult Function(String errorMessage) error,
|
||||
}) {
|
||||
return loaded(comment);
|
||||
@@ -403,7 +403,7 @@ class _$CommentsStateLoadedImpl implements CommentsStateLoaded {
|
||||
TResult? whenOrNull<TResult extends Object?>(
|
||||
TResult? Function()? $default, {
|
||||
TResult? Function()? loading,
|
||||
TResult? Function(Comment comment)? loaded,
|
||||
TResult? Function(CommentModel comment)? loaded,
|
||||
TResult? Function(String errorMessage)? error,
|
||||
}) {
|
||||
return loaded?.call(comment);
|
||||
@@ -414,7 +414,7 @@ class _$CommentsStateLoadedImpl implements CommentsStateLoaded {
|
||||
TResult maybeWhen<TResult extends Object?>(
|
||||
TResult Function()? $default, {
|
||||
TResult Function()? loading,
|
||||
TResult Function(Comment comment)? loaded,
|
||||
TResult Function(CommentModel comment)? loaded,
|
||||
TResult Function(String errorMessage)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
@@ -463,10 +463,10 @@ class _$CommentsStateLoadedImpl implements CommentsStateLoaded {
|
||||
}
|
||||
|
||||
abstract class CommentsStateLoaded implements CommentsState {
|
||||
const factory CommentsStateLoaded({required final Comment comment}) =
|
||||
const factory CommentsStateLoaded({required final CommentModel comment}) =
|
||||
_$CommentsStateLoadedImpl;
|
||||
|
||||
Comment get comment;
|
||||
CommentModel get comment;
|
||||
@JsonKey(ignore: true)
|
||||
_$$CommentsStateLoadedImplCopyWith<_$CommentsStateLoadedImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
@@ -540,7 +540,7 @@ class _$CommentsStateErrorImpl implements CommentsStateError {
|
||||
TResult when<TResult extends Object?>(
|
||||
TResult Function() $default, {
|
||||
required TResult Function() loading,
|
||||
required TResult Function(Comment comment) loaded,
|
||||
required TResult Function(CommentModel comment) loaded,
|
||||
required TResult Function(String errorMessage) error,
|
||||
}) {
|
||||
return error(errorMessage);
|
||||
@@ -551,7 +551,7 @@ class _$CommentsStateErrorImpl implements CommentsStateError {
|
||||
TResult? whenOrNull<TResult extends Object?>(
|
||||
TResult? Function()? $default, {
|
||||
TResult? Function()? loading,
|
||||
TResult? Function(Comment comment)? loaded,
|
||||
TResult? Function(CommentModel comment)? loaded,
|
||||
TResult? Function(String errorMessage)? error,
|
||||
}) {
|
||||
return error?.call(errorMessage);
|
||||
@@ -562,7 +562,7 @@ class _$CommentsStateErrorImpl implements CommentsStateError {
|
||||
TResult maybeWhen<TResult extends Object?>(
|
||||
TResult Function()? $default, {
|
||||
TResult Function()? loading,
|
||||
TResult Function(Comment comment)? loaded,
|
||||
TResult Function(CommentModel comment)? loaded,
|
||||
TResult Function(String errorMessage)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
|
||||
@@ -1,18 +1,47 @@
|
||||
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:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
class RecipesCubit extends Cubit<RecipesState> {
|
||||
final FeedRepository feedRepository;
|
||||
final RecipeRepository recipeRepository;
|
||||
Set<int> _selectedTags = {};
|
||||
|
||||
RecipesCubit({required this.feedRepository}) : super(const RecipesState.loading());
|
||||
RecipesCubit({
|
||||
required this.feedRepository,
|
||||
required this.recipeRepository,
|
||||
}) : super(const RecipesState.loading());
|
||||
|
||||
loadRecipesList() async {
|
||||
loadRecipesList({
|
||||
String? query,
|
||||
}) async {
|
||||
emit(const RecipesState.loading());
|
||||
try {
|
||||
final recipesList = await feedRepository.getRecipes();
|
||||
emit(RecipesState.loaded(recipesList: recipesList));
|
||||
print('asdasdasdasda');
|
||||
print(query);
|
||||
final recipesList = await feedRepository.getRecipes(
|
||||
tags: _selectedTags.toList(),
|
||||
query: query,
|
||||
);
|
||||
final recipesTags = (await recipeRepository.getRecipesTags());
|
||||
emit(RecipesState.loaded(
|
||||
recipesList: recipesList,
|
||||
recipesTags: recipesTags,
|
||||
selectedTags: _selectedTags,
|
||||
selectedTagsCounter: _selectedTags.length,
|
||||
));
|
||||
} catch (e) {
|
||||
emit(RecipesState.error(errorMessage: e.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
updateTags(RecipeTag tag) {
|
||||
_selectedTags.contains(tag.id) ? _selectedTags.remove(tag.id) : _selectedTags.add(tag.id);
|
||||
emit((state as RecipesStateLoaded).copyWith(
|
||||
selectedTags: _selectedTags,
|
||||
selectedTagsCounter: _selectedTags.length,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:eatvio_app/features/feed/models/recipes_model.dart';
|
||||
import 'package:eatvio_app/features/recipes/models/recipe_tag_model.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'recipes_state.freezed.dart';
|
||||
@@ -11,6 +12,9 @@ abstract class RecipesState with _$RecipesState {
|
||||
|
||||
const factory RecipesState.loaded({
|
||||
required List<Recipes> recipesList,
|
||||
required List<RecipeTag> recipesTags,
|
||||
required Set<int> selectedTags,
|
||||
required int selectedTagsCounter,
|
||||
}) = RecipesStateLoaded;
|
||||
|
||||
const factory RecipesState.error({
|
||||
|
||||
@@ -20,7 +20,12 @@ mixin _$RecipesState {
|
||||
TResult when<TResult extends Object?>(
|
||||
TResult Function() $default, {
|
||||
required TResult Function() loading,
|
||||
required TResult Function(List<Recipes> recipesList) loaded,
|
||||
required TResult Function(
|
||||
List<Recipes> recipesList,
|
||||
List<RecipeTag> recipesTags,
|
||||
Set<int> selectedTags,
|
||||
int selectedTagsCounter)
|
||||
loaded,
|
||||
required TResult Function(String errorMessage) error,
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@@ -28,7 +33,9 @@ mixin _$RecipesState {
|
||||
TResult? whenOrNull<TResult extends Object?>(
|
||||
TResult? Function()? $default, {
|
||||
TResult? Function()? loading,
|
||||
TResult? Function(List<Recipes> recipesList)? loaded,
|
||||
TResult? Function(List<Recipes> recipesList, List<RecipeTag> recipesTags,
|
||||
Set<int> selectedTags, int selectedTagsCounter)?
|
||||
loaded,
|
||||
TResult? Function(String errorMessage)? error,
|
||||
}) =>
|
||||
throw _privateConstructorUsedError;
|
||||
@@ -36,7 +43,9 @@ mixin _$RecipesState {
|
||||
TResult maybeWhen<TResult extends Object?>(
|
||||
TResult Function()? $default, {
|
||||
TResult Function()? loading,
|
||||
TResult Function(List<Recipes> recipesList)? loaded,
|
||||
TResult Function(List<Recipes> recipesList, List<RecipeTag> recipesTags,
|
||||
Set<int> selectedTags, int selectedTagsCounter)?
|
||||
loaded,
|
||||
TResult Function(String errorMessage)? error,
|
||||
required TResult orElse(),
|
||||
}) =>
|
||||
@@ -126,7 +135,12 @@ class _$RecipesStateImpl implements _RecipesState {
|
||||
TResult when<TResult extends Object?>(
|
||||
TResult Function() $default, {
|
||||
required TResult Function() loading,
|
||||
required TResult Function(List<Recipes> recipesList) loaded,
|
||||
required TResult Function(
|
||||
List<Recipes> recipesList,
|
||||
List<RecipeTag> recipesTags,
|
||||
Set<int> selectedTags,
|
||||
int selectedTagsCounter)
|
||||
loaded,
|
||||
required TResult Function(String errorMessage) error,
|
||||
}) {
|
||||
return $default();
|
||||
@@ -137,7 +151,9 @@ class _$RecipesStateImpl implements _RecipesState {
|
||||
TResult? whenOrNull<TResult extends Object?>(
|
||||
TResult? Function()? $default, {
|
||||
TResult? Function()? loading,
|
||||
TResult? Function(List<Recipes> recipesList)? loaded,
|
||||
TResult? Function(List<Recipes> recipesList, List<RecipeTag> recipesTags,
|
||||
Set<int> selectedTags, int selectedTagsCounter)?
|
||||
loaded,
|
||||
TResult? Function(String errorMessage)? error,
|
||||
}) {
|
||||
return $default?.call();
|
||||
@@ -148,7 +164,9 @@ class _$RecipesStateImpl implements _RecipesState {
|
||||
TResult maybeWhen<TResult extends Object?>(
|
||||
TResult Function()? $default, {
|
||||
TResult Function()? loading,
|
||||
TResult Function(List<Recipes> recipesList)? loaded,
|
||||
TResult Function(List<Recipes> recipesList, List<RecipeTag> recipesTags,
|
||||
Set<int> selectedTags, int selectedTagsCounter)?
|
||||
loaded,
|
||||
TResult Function(String errorMessage)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
@@ -241,7 +259,12 @@ class _$RecipesStateLoadingImpl implements RecipesStateLoading {
|
||||
TResult when<TResult extends Object?>(
|
||||
TResult Function() $default, {
|
||||
required TResult Function() loading,
|
||||
required TResult Function(List<Recipes> recipesList) loaded,
|
||||
required TResult Function(
|
||||
List<Recipes> recipesList,
|
||||
List<RecipeTag> recipesTags,
|
||||
Set<int> selectedTags,
|
||||
int selectedTagsCounter)
|
||||
loaded,
|
||||
required TResult Function(String errorMessage) error,
|
||||
}) {
|
||||
return loading();
|
||||
@@ -252,7 +275,9 @@ class _$RecipesStateLoadingImpl implements RecipesStateLoading {
|
||||
TResult? whenOrNull<TResult extends Object?>(
|
||||
TResult? Function()? $default, {
|
||||
TResult? Function()? loading,
|
||||
TResult? Function(List<Recipes> recipesList)? loaded,
|
||||
TResult? Function(List<Recipes> recipesList, List<RecipeTag> recipesTags,
|
||||
Set<int> selectedTags, int selectedTagsCounter)?
|
||||
loaded,
|
||||
TResult? Function(String errorMessage)? error,
|
||||
}) {
|
||||
return loading?.call();
|
||||
@@ -263,7 +288,9 @@ class _$RecipesStateLoadingImpl implements RecipesStateLoading {
|
||||
TResult maybeWhen<TResult extends Object?>(
|
||||
TResult Function()? $default, {
|
||||
TResult Function()? loading,
|
||||
TResult Function(List<Recipes> recipesList)? loaded,
|
||||
TResult Function(List<Recipes> recipesList, List<RecipeTag> recipesTags,
|
||||
Set<int> selectedTags, int selectedTagsCounter)?
|
||||
loaded,
|
||||
TResult Function(String errorMessage)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
@@ -321,7 +348,11 @@ abstract class _$$RecipesStateLoadedImplCopyWith<$Res> {
|
||||
$Res Function(_$RecipesStateLoadedImpl) then) =
|
||||
__$$RecipesStateLoadedImplCopyWithImpl<$Res>;
|
||||
@useResult
|
||||
$Res call({List<Recipes> recipesList});
|
||||
$Res call(
|
||||
{List<Recipes> recipesList,
|
||||
List<RecipeTag> recipesTags,
|
||||
Set<int> selectedTags,
|
||||
int selectedTagsCounter});
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@@ -336,12 +367,27 @@ class __$$RecipesStateLoadedImplCopyWithImpl<$Res>
|
||||
@override
|
||||
$Res call({
|
||||
Object? recipesList = null,
|
||||
Object? recipesTags = null,
|
||||
Object? selectedTags = null,
|
||||
Object? selectedTagsCounter = null,
|
||||
}) {
|
||||
return _then(_$RecipesStateLoadedImpl(
|
||||
recipesList: null == recipesList
|
||||
? _value._recipesList
|
||||
: recipesList // ignore: cast_nullable_to_non_nullable
|
||||
as List<Recipes>,
|
||||
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,
|
||||
));
|
||||
}
|
||||
}
|
||||
@@ -349,8 +395,14 @@ class __$$RecipesStateLoadedImplCopyWithImpl<$Res>
|
||||
/// @nodoc
|
||||
|
||||
class _$RecipesStateLoadedImpl implements RecipesStateLoaded {
|
||||
const _$RecipesStateLoadedImpl({required final List<Recipes> recipesList})
|
||||
: _recipesList = recipesList;
|
||||
const _$RecipesStateLoadedImpl(
|
||||
{required final List<Recipes> recipesList,
|
||||
required final List<RecipeTag> recipesTags,
|
||||
required final Set<int> selectedTags,
|
||||
required this.selectedTagsCounter})
|
||||
: _recipesList = recipesList,
|
||||
_recipesTags = recipesTags,
|
||||
_selectedTags = selectedTags;
|
||||
|
||||
final List<Recipes> _recipesList;
|
||||
@override
|
||||
@@ -360,9 +412,28 @@ class _$RecipesStateLoadedImpl implements RecipesStateLoaded {
|
||||
return EqualUnmodifiableListView(_recipesList);
|
||||
}
|
||||
|
||||
final List<RecipeTag> _recipesTags;
|
||||
@override
|
||||
List<RecipeTag> get recipesTags {
|
||||
if (_recipesTags is EqualUnmodifiableListView) return _recipesTags;
|
||||
// ignore: implicit_dynamic_type
|
||||
return EqualUnmodifiableListView(_recipesTags);
|
||||
}
|
||||
|
||||
final Set<int> _selectedTags;
|
||||
@override
|
||||
Set<int> get selectedTags {
|
||||
if (_selectedTags is EqualUnmodifiableSetView) return _selectedTags;
|
||||
// ignore: implicit_dynamic_type
|
||||
return EqualUnmodifiableSetView(_selectedTags);
|
||||
}
|
||||
|
||||
@override
|
||||
final int selectedTagsCounter;
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'RecipesState.loaded(recipesList: $recipesList)';
|
||||
return 'RecipesState.loaded(recipesList: $recipesList, recipesTags: $recipesTags, selectedTags: $selectedTags, selectedTagsCounter: $selectedTagsCounter)';
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -371,12 +442,22 @@ class _$RecipesStateLoadedImpl implements RecipesStateLoaded {
|
||||
(other.runtimeType == runtimeType &&
|
||||
other is _$RecipesStateLoadedImpl &&
|
||||
const DeepCollectionEquality()
|
||||
.equals(other._recipesList, _recipesList));
|
||||
.equals(other._recipesList, _recipesList) &&
|
||||
const DeepCollectionEquality()
|
||||
.equals(other._recipesTags, _recipesTags) &&
|
||||
const DeepCollectionEquality()
|
||||
.equals(other._selectedTags, _selectedTags) &&
|
||||
(identical(other.selectedTagsCounter, selectedTagsCounter) ||
|
||||
other.selectedTagsCounter == selectedTagsCounter));
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(
|
||||
runtimeType, const DeepCollectionEquality().hash(_recipesList));
|
||||
runtimeType,
|
||||
const DeepCollectionEquality().hash(_recipesList),
|
||||
const DeepCollectionEquality().hash(_recipesTags),
|
||||
const DeepCollectionEquality().hash(_selectedTags),
|
||||
selectedTagsCounter);
|
||||
|
||||
@JsonKey(ignore: true)
|
||||
@override
|
||||
@@ -390,10 +471,15 @@ class _$RecipesStateLoadedImpl implements RecipesStateLoaded {
|
||||
TResult when<TResult extends Object?>(
|
||||
TResult Function() $default, {
|
||||
required TResult Function() loading,
|
||||
required TResult Function(List<Recipes> recipesList) loaded,
|
||||
required TResult Function(
|
||||
List<Recipes> recipesList,
|
||||
List<RecipeTag> recipesTags,
|
||||
Set<int> selectedTags,
|
||||
int selectedTagsCounter)
|
||||
loaded,
|
||||
required TResult Function(String errorMessage) error,
|
||||
}) {
|
||||
return loaded(recipesList);
|
||||
return loaded(recipesList, recipesTags, selectedTags, selectedTagsCounter);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -401,10 +487,13 @@ class _$RecipesStateLoadedImpl implements RecipesStateLoaded {
|
||||
TResult? whenOrNull<TResult extends Object?>(
|
||||
TResult? Function()? $default, {
|
||||
TResult? Function()? loading,
|
||||
TResult? Function(List<Recipes> recipesList)? loaded,
|
||||
TResult? Function(List<Recipes> recipesList, List<RecipeTag> recipesTags,
|
||||
Set<int> selectedTags, int selectedTagsCounter)?
|
||||
loaded,
|
||||
TResult? Function(String errorMessage)? error,
|
||||
}) {
|
||||
return loaded?.call(recipesList);
|
||||
return loaded?.call(
|
||||
recipesList, recipesTags, selectedTags, selectedTagsCounter);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -412,12 +501,15 @@ class _$RecipesStateLoadedImpl implements RecipesStateLoaded {
|
||||
TResult maybeWhen<TResult extends Object?>(
|
||||
TResult Function()? $default, {
|
||||
TResult Function()? loading,
|
||||
TResult Function(List<Recipes> recipesList)? loaded,
|
||||
TResult Function(List<Recipes> recipesList, List<RecipeTag> recipesTags,
|
||||
Set<int> selectedTags, int selectedTagsCounter)?
|
||||
loaded,
|
||||
TResult Function(String errorMessage)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
if (loaded != null) {
|
||||
return loaded(recipesList);
|
||||
return loaded(
|
||||
recipesList, recipesTags, selectedTags, selectedTagsCounter);
|
||||
}
|
||||
return orElse();
|
||||
}
|
||||
@@ -461,10 +553,16 @@ class _$RecipesStateLoadedImpl implements RecipesStateLoaded {
|
||||
}
|
||||
|
||||
abstract class RecipesStateLoaded implements RecipesState {
|
||||
const factory RecipesStateLoaded({required final List<Recipes> recipesList}) =
|
||||
_$RecipesStateLoadedImpl;
|
||||
const factory RecipesStateLoaded(
|
||||
{required final List<Recipes> recipesList,
|
||||
required final List<RecipeTag> recipesTags,
|
||||
required final Set<int> selectedTags,
|
||||
required final int selectedTagsCounter}) = _$RecipesStateLoadedImpl;
|
||||
|
||||
List<Recipes> get recipesList;
|
||||
List<RecipeTag> get recipesTags;
|
||||
Set<int> get selectedTags;
|
||||
int get selectedTagsCounter;
|
||||
@JsonKey(ignore: true)
|
||||
_$$RecipesStateLoadedImplCopyWith<_$RecipesStateLoadedImpl> get copyWith =>
|
||||
throw _privateConstructorUsedError;
|
||||
@@ -538,7 +636,12 @@ class _$RecipesStateErrorImpl implements RecipesStateError {
|
||||
TResult when<TResult extends Object?>(
|
||||
TResult Function() $default, {
|
||||
required TResult Function() loading,
|
||||
required TResult Function(List<Recipes> recipesList) loaded,
|
||||
required TResult Function(
|
||||
List<Recipes> recipesList,
|
||||
List<RecipeTag> recipesTags,
|
||||
Set<int> selectedTags,
|
||||
int selectedTagsCounter)
|
||||
loaded,
|
||||
required TResult Function(String errorMessage) error,
|
||||
}) {
|
||||
return error(errorMessage);
|
||||
@@ -549,7 +652,9 @@ class _$RecipesStateErrorImpl implements RecipesStateError {
|
||||
TResult? whenOrNull<TResult extends Object?>(
|
||||
TResult? Function()? $default, {
|
||||
TResult? Function()? loading,
|
||||
TResult? Function(List<Recipes> recipesList)? loaded,
|
||||
TResult? Function(List<Recipes> recipesList, List<RecipeTag> recipesTags,
|
||||
Set<int> selectedTags, int selectedTagsCounter)?
|
||||
loaded,
|
||||
TResult? Function(String errorMessage)? error,
|
||||
}) {
|
||||
return error?.call(errorMessage);
|
||||
@@ -560,7 +665,9 @@ class _$RecipesStateErrorImpl implements RecipesStateError {
|
||||
TResult maybeWhen<TResult extends Object?>(
|
||||
TResult Function()? $default, {
|
||||
TResult Function()? loading,
|
||||
TResult Function(List<Recipes> recipesList)? loaded,
|
||||
TResult Function(List<Recipes> recipesList, List<RecipeTag> recipesTags,
|
||||
Set<int> selectedTags, int selectedTagsCounter)?
|
||||
loaded,
|
||||
TResult Function(String errorMessage)? error,
|
||||
required TResult orElse(),
|
||||
}) {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import 'package:easy_debounce/easy_debounce.dart';
|
||||
import 'package:eatvio_app/features/feed/presentation/bloc/diets_cubit/diets_cubit.dart';
|
||||
import 'package:eatvio_app/features/feed/presentation/bloc/diets_cubit/diets_state.dart';
|
||||
import 'package:eatvio_app/features/feed/presentation/bloc/feed_cubit/feed_cubit.dart';
|
||||
@@ -7,6 +8,7 @@ import 'package:eatvio_app/features/feed/presentation/bloc/recipes_cubit/recipes
|
||||
import 'package:eatvio_app/features/feed/presentation/widgets/blog_post_widget.dart';
|
||||
import 'package:eatvio_app/features/feed/presentation/widgets/diets_widget.dart';
|
||||
import 'package:eatvio_app/features/feed/presentation/widgets/recipes_widget.dart';
|
||||
import 'package:eatvio_app/features/feed/presentation/widgets/tags_modal_widget.dart';
|
||||
import 'package:eatvio_app/theme/theme_helper.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@@ -21,13 +23,44 @@ class FeedScreen extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _FeedScreenState extends State<FeedScreen> {
|
||||
final searchController = TextEditingController();
|
||||
final List<String> chipsLabelList = ['Все', 'Рецепты', 'Диеты', 'Планы питания', 'Консультанты'];
|
||||
|
||||
int _selectedChipIndex = 0;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
floatingActionButton: _selectedChipIndex == 1
|
||||
? FloatingActionButton.small(
|
||||
backgroundColor: appTheme.blueA400,
|
||||
shape: CircleBorder(),
|
||||
child: Icon(
|
||||
Icons.filter_list_rounded,
|
||||
color: Colors.white,
|
||||
),
|
||||
onPressed: () async {
|
||||
await showModalBottomSheet(
|
||||
useRootNavigator: true,
|
||||
context: context,
|
||||
builder: (context) {
|
||||
return BlocBuilder<RecipesCubit, RecipesState>(
|
||||
builder: (BuildContext context, RecipesState state) {
|
||||
if (state is RecipesStateLoaded) {
|
||||
return TagsModalWidget(
|
||||
tagsList: state.recipesTags,
|
||||
selectedTags: state.selectedTags,
|
||||
);
|
||||
} else {
|
||||
return Container();
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
context.read<RecipesCubit>().loadRecipesList();
|
||||
},
|
||||
)
|
||||
: null,
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.white,
|
||||
toolbarHeight: 0,
|
||||
@@ -85,7 +118,7 @@ class _FeedScreenState extends State<FeedScreen> {
|
||||
shrinkWrap: true,
|
||||
physics: BouncingScrollPhysics(),
|
||||
itemBuilder: (context, index) {
|
||||
return DietsWidget(datum: state.diets.data[index]);
|
||||
return DietsWidget(diet: state.diets.data[index]);
|
||||
},
|
||||
separatorBuilder: (context, index) {
|
||||
return SizedBox(height: 8);
|
||||
@@ -247,9 +280,35 @@ class _FeedScreenState extends State<FeedScreen> {
|
||||
height: 40,
|
||||
width: MediaQuery.of(context).size.width - 84,
|
||||
child: TextFormField(
|
||||
controller: searchController,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
),
|
||||
onChanged: (query) {
|
||||
if (query.length > 2) {
|
||||
EasyDebounce.debounce(
|
||||
'searchFeed',
|
||||
Duration(milliseconds: 500),
|
||||
() {
|
||||
switch (_selectedChipIndex) {
|
||||
case 1:
|
||||
context.read<RecipesCubit>().loadRecipesList(query: query);
|
||||
}
|
||||
},
|
||||
);
|
||||
} else {
|
||||
EasyDebounce.debounce(
|
||||
'searchFeed',
|
||||
Duration(milliseconds: 500),
|
||||
() {
|
||||
switch (_selectedChipIndex) {
|
||||
case 1:
|
||||
context.read<RecipesCubit>().loadRecipesList(query: query);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
},
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Поиск',
|
||||
hintStyle: TextStyle(
|
||||
@@ -304,6 +363,8 @@ class _FeedScreenState extends State<FeedScreen> {
|
||||
onSelected: (bool selected) {
|
||||
setState(() {
|
||||
_selectedChipIndex = index;
|
||||
searchController.clear();
|
||||
FocusScope.of(context).requestFocus(new FocusNode());
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
@@ -5,9 +5,9 @@ import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
class DietsWidget extends StatefulWidget {
|
||||
final Datum datum;
|
||||
final Diet diet;
|
||||
|
||||
const DietsWidget({super.key, required this.datum});
|
||||
const DietsWidget({super.key, required this.diet});
|
||||
|
||||
@override
|
||||
State<DietsWidget> createState() => _DietsWidgetState();
|
||||
@@ -18,7 +18,7 @@ class _DietsWidgetState extends State<DietsWidget> {
|
||||
Widget build(BuildContext context) {
|
||||
return InkWell(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
onTap: () => GoRouter.of(context).pushNamed('aboutDietScreen', extra: widget.datum),
|
||||
onTap: () => GoRouter.of(context).pushNamed('aboutDietScreen', extra: widget.diet),
|
||||
child: Ink(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
@@ -33,7 +33,7 @@ class _DietsWidgetState extends State<DietsWidget> {
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(12)),
|
||||
child: CachedNetworkImage(
|
||||
imageUrl: baseUrl + '/storage/' + widget.datum.image,
|
||||
imageUrl: baseUrl + '/storage/' + widget.diet.image,
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
@@ -44,9 +44,9 @@ class _DietsWidgetState extends State<DietsWidget> {
|
||||
children: [
|
||||
_iconButton(Icons.fastfood, '139.9 ккал'),
|
||||
SizedBox(width: 8),
|
||||
_iconButton(Icons.timer_rounded, widget.datum.state),
|
||||
_iconButton(Icons.timer_rounded, widget.diet.state),
|
||||
SizedBox(width: 8),
|
||||
_iconButton(Icons.fast_forward_rounded, widget.datum.duration.toString()),
|
||||
_iconButton(Icons.fast_forward_rounded, widget.diet.duration.toString()),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -68,7 +68,7 @@ class _DietsWidgetState extends State<DietsWidget> {
|
||||
),
|
||||
SizedBox(width: 4),
|
||||
Text(
|
||||
widget.datum.totalLikes.toString(),
|
||||
widget.diet.totalLikes.toString(),
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.black,
|
||||
@@ -97,7 +97,7 @@ class _DietsWidgetState extends State<DietsWidget> {
|
||||
),
|
||||
SizedBox(width: 4),
|
||||
Text(
|
||||
widget.datum.totalViews.toString(),
|
||||
widget.diet.totalViews.toString(),
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: Colors.black,
|
||||
@@ -114,7 +114,7 @@ class _DietsWidgetState extends State<DietsWidget> {
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
child: Text(
|
||||
widget.datum.name,
|
||||
widget.diet.name,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w600,
|
||||
color: Colors.black87,
|
||||
@@ -125,7 +125,7 @@ class _DietsWidgetState extends State<DietsWidget> {
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
child: Text(
|
||||
widget.datum.details,
|
||||
widget.diet.details,
|
||||
style: TextStyle(
|
||||
color: Colors.black87,
|
||||
),
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
import 'package:eatvio_app/features/feed/presentation/bloc/recipes_cubit/recipes_cubit.dart';
|
||||
import 'package:eatvio_app/features/recipes/models/recipe_tag_model.dart';
|
||||
import 'package:eatvio_app/theme/theme_helper.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
class TagsModalWidget extends StatefulWidget {
|
||||
final List<RecipeTag> tagsList;
|
||||
final Set<int> selectedTags;
|
||||
|
||||
const TagsModalWidget({
|
||||
super.key,
|
||||
required this.tagsList,
|
||||
required this.selectedTags,
|
||||
});
|
||||
|
||||
@override
|
||||
State<TagsModalWidget> createState() => _TagsModalWidgetState();
|
||||
}
|
||||
|
||||
class _TagsModalWidgetState extends State<TagsModalWidget> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Container(
|
||||
padding: EdgeInsets.all(16),
|
||||
width: MediaQuery.of(context).size.width,
|
||||
child: Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: -8,
|
||||
children: [
|
||||
for (int i = 0; i < widget.tagsList.length; i++)
|
||||
_tagChip(
|
||||
tag: widget.tagsList[i],
|
||||
isSelected: widget.selectedTags.contains(widget.tagsList[i].id),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
_tagChip({
|
||||
required RecipeTag tag,
|
||||
required bool isSelected,
|
||||
}) {
|
||||
return ChoiceChip(
|
||||
selectedColor: appTheme.blueA400,
|
||||
pressElevation: 0,
|
||||
showCheckmark: false,
|
||||
side: BorderSide.none,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||
label: Text(tag.name),
|
||||
labelStyle: TextStyle(
|
||||
color: isSelected ? Colors.white : appTheme.gray600,
|
||||
fontWeight: FontWeight.w500,
|
||||
fontSize: 12,
|
||||
),
|
||||
selected: isSelected,
|
||||
backgroundColor: appTheme.gray100,
|
||||
onSelected: (bool selected) => context.read<RecipesCubit>().updateTags(tag),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user