forked from eatvio/eatvio_app
feat(recipe): my recipes screen
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import 'package:eatvio_app/features/recipe/presentation/cubit/my_recipes_cubit/my_recipes_state.dart';
|
||||
import 'package:eatvio_app/features/recipe/repositories/my_recipes_repository.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
class MyRecipesCubit extends Cubit<MyRecipesState> {
|
||||
final MyRecipesRepository myRecipesRepository;
|
||||
|
||||
MyRecipesCubit({
|
||||
required this.myRecipesRepository,
|
||||
}) : super(const MyRecipesState.loading());
|
||||
|
||||
getMyRecipes() async {
|
||||
emit(const MyRecipesState.loading());
|
||||
try {
|
||||
final myRecipes = await myRecipesRepository.getMyRecipes();
|
||||
emit(MyRecipesState.loaded(recipes: myRecipes));
|
||||
} catch (e) {
|
||||
emit(const MyRecipesState.error());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import 'package:eatvio_app/features/recipe/models/my_recipe_model.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'my_recipes_state.freezed.dart';
|
||||
|
||||
@freezed
|
||||
abstract class MyRecipesState with _$MyRecipesState {
|
||||
const factory MyRecipesState() = _MyRecipesState;
|
||||
|
||||
const factory MyRecipesState.loading() = MyRecipesStateLoading;
|
||||
|
||||
const factory MyRecipesState.loaded({
|
||||
required List<MyRecipeModel> recipes,
|
||||
}) = MyRecipesStateLoaded;
|
||||
|
||||
const factory MyRecipesState.error() = MyRecipesStateError;
|
||||
}
|
||||
Reference in New Issue
Block a user