8000 Buat fitur menampilkan daftar favorite meals di UI Favorite Meal · CoderJava/Food-Recipe@2f3519b · GitHub
[go: up one dir, main page]

Skip to content

Commit 2f3519b

Browse files
committed
Buat fitur menampilkan daftar favorite meals di UI Favorite Meal
1 parent db71b3c commit 2f3519b

13 files changed

+460
-112
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import 'package:food_recipe/src/database/entity/favorite_meal.dart';
2+
import 'package:food_recipe/src/database/repository/favorite_meal_repository.dart';
3+
import 'package:rxdart/rxdart.dart';
4+
5+
import 'favorite_meals_bloc_model.dart';
6+
7+
class FavoriteBloc {
8+
final _favoriteMealRepository = FavoriteMealRepository();
9+
var _publishSubjectListFavoriteMeal =
10+
PublishSubject<FavoriteMealsBlocModel>();
11+
12+
dispose() {
13+
_publishSubjectListFavoriteMeal.close();
14+
}
15+
16+
Observable<FavoriteMealsBlocModel> get listFavoriteMeal =>
17+
_publishSubjectListFavoriteMeal.stream;
18+
19+
getAllFavoriteMeals() async {
20+
_publishSubjectListFavoriteMeal.sink
21+
.add(FavoriteMealsBlocModel(isLoading: true));
22+
List<FavoriteMeal> listFavoriteMeals =
23+
await _favoriteMealRepository.getAllFavoriteMeals();
24+
FavoriteMealsBlocModel favoriteMealsBlocModel =
25+
FavoriteMealsBlocModel(listFavoriteMeals: listFavoriteMeals);
26+
_publishSubjectListFavoriteMeal.sink.add(favoriteMealsBlocModel);
27+
}
28+
29+
removeFavoriteMealById(String id) async {
30+
_publishSubjectListFavoriteMeal.sink.add(FavoriteMealsBlocModel(isLoading: true));
31+
await _favoriteMealRepository.deleteFavoriteMealById(id);
32+
List<FavoriteMeal> listFavoriteMeals =
33+
await _favoriteMealRepository.getAllFavoriteMeals();
34+
FavoriteMealsBlocModel favoriteMealsBlocModel =
35+
FavoriteMealsBlocModel(listFavoriteMeals: listFavoriteMeals);
36+
_publishSubjectListFavoriteMeal.sink.add(favoriteMealsBlocModel);
37+
}
38+
39+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import 'package:food_recipe/src/database/entity/favorite_meal.dart';
2+
3+
class FavoriteMealsBlocModel {
4+
List<FavoriteMeal> listFavoriteMeals;
5+
bool isLoading;
6+
7+
FavoriteMealsBlocModel({this.listFavoriteMeals, this.isLoading = false,});
8+
9+
@override
10+
String toString() {
11+
return 'FavoriteMealsBlocModel{listFavoriteMeals: $listFavoriteMeals, isLoading: $isLoading}';
12+
}
13+
14+
}

lib/src/blocs/home/home_bloc.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import 'package:food_recipe/src/resources/food_api_repository.dart';
55
class HomeBloc {
66
final _repository = FoodApiRepository();
77

8+
dispose() {
9+
// TODO: do something in here
10+
}
11+
812
Future<LatestMeals> getLatestMeals() async {
913
return await _repository.getLatestMeals();
1014
}
@@ -13,10 +17,6 @@ class HomeBloc {
1317
return await _repository.getCategories();
1418
}
1519

16-
dispose() {
17-
// TODO: do something in here
18-
}
19-
2020
}
2121

2222
final homeBloc = HomeBloc();

lib/src/blocs/listmeals/list_meals_bloc.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ class ListMealsBloc {
88
final _foodApiRepository = FoodApiRepository();
99
final _favoriteMealRepository = FavoriteMealRepository();
1010

11+
dispose() {
12+
// TODO: do something in here
13+
}
14+
1115
Future<FilterCategories> getFilterCategories(String category) async {
1216
FilterCategories filterCategories =
1317
await _foodApiRepository.getFilterByCategories(category);
@@ -41,10 +45,6 @@ class ListMealsBloc {
4145
Future<int> deleteFavoriteMealById(String id) async {
4246
return await _favoriteMealRepository.deleteFavoriteMealById(id);
4347
}
44-
45-
dispose() {
46-
// TODO: do something in here
47-
}
4848
}
4949

5050
final listMealsBloc = ListMealsBloc();

lib/src/database/database.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class DatabaseProvider {
2828

2929
void onUpgrade(Database database, int oldVersion, int newVersion) {
3030
if (newVersion > oldVersion) {
31-
// TODO: do something in here if needed
31+
// TODO: do something in here if needed to upgrade database version
3232
}
3333
}
3434

@@ -41,6 +41,7 @@ class DatabaseProvider {
4141
"strTags TEXT, "
4242
"strYoutube TEXT, "
4343
"strArea TEXT, "
44+
"strInstructions TEXT, "
4445
"strIngredient1 TEXT, "
4546
"strIngredient2 TEXT, "
4647
"strIngredient3 TEXT, "

lib/src/database/entity/favorite_meal.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class FavoriteMeal {
1111
String strTags;
1212
String strYoutube;
1313
String strArea;
14+
String strInstructions;
1415
String strIngredient1;
1516
String strIngredient2;
1617
String strIngredient3;
@@ -60,6 +61,7 @@ class FavoriteMeal {
6061
this.strTags,
6162
this.strYoutube,
6263
this.strArea,
64+
this.strInstructions,
6365
this.strIngredient1,
6466
this.strIngredient2,
6567
this.strIngredient3,
@@ -103,7 +105,7 @@ class FavoriteMeal {
103105

104106
@override
105107
String toString() {
106-
return 'FavoriteMeal{id: $idMeal, strMeal: $strMeal, strMealThumb: $strMealThumb, strCategory: $strCategory, strTags: $strTags, strYoutube: $strYoutube, strArea: $strArea, strIngredient1: $strIngredient1, strIngredient2: $strIngredient2, strIngredient3: $strIngredient3, strIngredient4: $strIngredient4, strIngredient5: $strIngredient5, strIngredient6: $strIngredient6, strIngredient7: $strIngredient7, strIngredient8: $strIngredient8, strIngredient9: $strIngredient9, strIngredient10: $strIngredient10, strIngredient11: $strIngredient11, strIngredient12: $strIngredient12, strIngredient13: $strIngredient13, strIngredient14: $strIngredient14, strIngredient15: $strIngredient15, strIngredient16: $strIngredient16, strIngredient17: $strIngredient17, strIngredient18: $strIngredient18, strIngredient19: $strIngredient19, strIngredient20: $strIngredient20, strMeasure1: $strMeasure1, strMeasure2: $strMeasure2, strMeasure3: $strMeasure3, strMeasure4: $strMeasure4, strMeasure5: $strMeasure5, strMeasure6: $strMeasure6, strMeasure7: $strMeasure7, strMeasure8: $strMeasure8, strMeasure9: $strMeasure9, strMeasure10: $strMeasure10, strMeasure11: $strMeasure11, strMeasure12: $strMeasure12, strMeasure13: $strMeasure13, strMeasure14: $strMeasure14, strMeasure15: $strMeasure15, strMeasure16: $strMeasure16, strMeasure17: $strMeasure17, strMeasure18: $strMeasure18, strMeasure19: $strMeasure19, strMeasure20: $strMeasure20}';
108+
return 'FavoriteMeal{idMeal: $idMeal, strMeal: $strMeal, strMealThumb: $strMealThumb, strCategory: $strCategory, strTags: $strTags, strYoutube: $strYoutube, strArea: $strArea, strInstructions: $strInstructions, strIngredient1: $strIngredient1, strIngredient2: $strIngredient2, strIngredient3: $strIngredient3, strIngredient4: $strIngredient4, strIngredient5: $strIngredient5, strIngredient6: $strIngredient6, strIngredient7: $strIngredient7, strIngredient8: $strIngredient8, strIngredient9: $strIngredient9, strIngredient10: $strIngredient10, strIngredient11: $strIngredient11, strIngredient12: $strIngredient12, strIngredient13: $strIngredient13, strIngredient14: $strIngredient14, strIngredient15: $strIngredient15, strIngredient16: $strIngredient16, strIngredient17: $strIngredient17, strIngredient18: $strIngredient18, strIngredient19: $strIngredient19, strIngredient20: $strIngredient20, strMeasure1: $strMeasure1, strMeasure2: $strMeasure2, strMeasure3: $strMeasure3, strMeasure4: $strMeasure4, strMeasure5: $strMeasure5, strMeasure6: $strMeasure6, strMeasure7: $strMeasure7, strMeasure8: $strMeasure8, strMeasure9: $strMeasure9, strMeasure10: $strMeasure10, strMeasure11: $strMeasure11, strMeasure12: $strMeasure12, strMeasure13: $strMeasure13, strMeasure14: $strMeasure14, strMeasure15: $strMeasure15, strMeasure16: $strMeasure16, strMeasure17: $strMeasure17, strMeasure18: $strMeasure18, strMeasure19: $strMeasure19, strMeasure20: $strMeasure20}';
107109
}
108110

109111
factory FavoriteMeal.fromJson(Map<String, dynamic> json) =>

lib/src/database/entity/favorite_meal.g.dart

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
0