Skip to content

Commit 01016b3

Browse files
committed
Buat konten daftar makanan di UI List Meals
1 parent 9e52922 commit 01016b3

File tree

3 files changed

+142
-13
lines changed

3 files changed

+142
-13
lines changed

lib/src/blocs/list_meals_bloc.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import 'package:food_recipe/src/models/filtercategories/filter_categories.dart';
2+
import 'package:food_recipe/src/resources/repository.dart';
3+
4+
class ListMealsBloc {
5+
final repository = Repository();
6+
7+
Future<FilterCategories> getFilterCategories(String category) async {
8+
return await repository.getFilterByCategories(category);
9+
}
10+
11+
dispose() {
12+
// TODO: do something in here
13+
}
14+
15+
}
16+
17+
final listMealsBloc = ListMealsBloc();

lib/src/ui/home/home_screen.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class _HomeScreenState extends State<HomeScreen> {
115115
padding: const EdgeInsets.only(right: 4.0),
116116
child: GestureDetector(
117117
onTap: () {
118-
Navigator.pushNamed(context, navigatorListMeals);
118+
Navigator.pushNamed(context, navigatorListMeals, arguments: category);
119119
},
120120
child: Card(
121121
shape: RoundedRectangleBorder(

lib/src/ui/listmeals/list_meals.dart

Lines changed: 124 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,154 @@
1-
import 'dart:io';
2-
31
import 'package:flutter/cupertino.dart';
42
import 'package:flutter/material.dart';
3+
import 'package:food_recipe/src/blocs/list_meals_bloc.dart';
4+
import 'package:food_recipe/src/models/categories/categories.dart';
5+
import 'package:food_recipe/src/models/filtercategories/filter_categories.dart';
6+
import 'package:food_recipe/src/utils/utils.dart';
57

68
class ListMeals extends StatefulWidget {
79
@override
810
_ListMealsState createState() => _ListMealsState();
911
}
1012

1113
class _ListMealsState extends State<ListMeals> {
14+
CategoryItem categoryItem;
15+
16+
@override
17+
void initState() {
18+
super.initState();
19+
}
20+
1221
@override
1322
Widget build(BuildContext context) {
1423
var mediaQuery = MediaQuery.of(context);
24+
categoryItem = ModalRoute.of(context).settings.arguments;
25+
1526
return Scaffold(
1627
body: Container(
1728
width: double.infinity,
1829
height: double.infinity,
1930
child: Stack(
2031
children: <Widget>[
2132
_buildWidgetBackgroundCircle(mediaQuery),
22-
_buildWidgetArrowBackMenu(),
33+
_buildWidgetContent(mediaQuery),
2334
],
2435
),
2536
),
2637
);
2738
}
2839

29-
Widget _buildWidgetArrowBackMenu() {
40+
Widget _buildWidgetContent(MediaQueryData mediaQuery) {
3041
return SafeArea(
31-
minimum: EdgeInsets.symmetric(horizontal: 16.0),
32-
child: CircleAvatar(
33-
child: Platform.isIOS
34-
? Icon(Icons.arrow_back_ios, color: Colors.black)
35-
: Icon(Icons.arrow_back, color: Colors.black),
36-
maxRadius: 24.0,
37-
backgroundColor: Colors.white,
42+
minimum: EdgeInsets.symmetric(horizontal: 16.0),
43+
child: Column(
44+
crossAxisAlignment: CrossAxisAlignment.start,
45+
children: <Widget>[
46+
Padding(padding: EdgeInsets.only(top: 16.0)),
47+
Text(
48+
categoryItem.strCategory,
49+
style: Theme.of(context)
50+
.textTheme
51+
.display2
52+
.merge(TextStyle(fontWeight: FontWeight.bold)),
53+
maxLines: 1,
54+
),
55+
Padding(padding: EdgeInsets.only(top: 16.0)),
56+
Expanded(
57+
child: FutureBuilder(
58+
future:
59+
listMealsBloc.getFilterCategories(categoryItem.strCategory),
60+
builder: (BuildContext context,
61+
AsyncSnapshot<FilterCategories> snapshot) {
62+
if (snapshot.hasData) {
63+
FilterCategories filterCategories = snapshot.data;
64+
return ListView.builder(
65+
shrinkWrap: true,
66+
itemCount: filterCategories.filterCategoryItems.length,
67+
itemBuilder: (context, index) {
68+
FilterCategoryItem filterCategoryItem =
69+
filterCategories.filterCategoryItems[index];
70+
return Padding(
71+
padding: const EdgeInsets.only(bottom: 16.0),
72+
child: Card(
73+
elevation: 8.0,
74+
shape: RoundedRectangleBorder(
75+
borderRadius: BorderRadius.circular(16.0),
76+
),
77+
child: ClipRRect(
78+
borderRadius: BorderRadius.circular(16.0),
79+
child: Stack(
80+
children: <Widget>[
81+
FadeInImage(
82+
image: NetworkImage(
83+
filterCategoryItem.strMealThumb),
84+
placeholder: AssetImage(
85+
"assets/images/img_not_found.jpg"),
86+
fit: BoxFit.cover,
87+
width: double.infinity,
88+
height: mediaQuery.size.width / 1.5,
89+
),
90+
Container(
91+
width: double.infinity,
92+
height: mediaQuery.size.width / 1.5,
93+
decoration: BoxDecoration(
94+
gradient: LinearGradient(
95+
begin: Alignment.topCenter,
96+
end: Alignment.bottomCenter,
97+
stops: [
98+
0.1,
99+
0.9
100+
],
101+
colors: [
102+
Color(0xFFFFFFFF),
103+
Color(0x00FFFFFF),
104+
]),
105+
),
106+
),
107+
Padding(
108+
padding: const EdgeInsets.all(16.0),
109+
child: Row(
110+
crossAxisAlignment: CrossAxisAlignment.start,
111+
children: <Widget>[
112+
Expanded(
113+
child: Text(
114+
filterCategoryItem.strMeal,
115+
style:
116+
Theme.of(context).textTheme.title,
117+
maxLines: 2,
118+
),
119+
),
120+
GestureDetector(
121+
onTap: () {
122+
// TODO: do something in here
123+
},
124+
child: CircleAvatar(
125+
backgroundColor: Color(0xAFE8364B),
126+
child: Icon(
127+
Icons.favorite_border,
128+
color: Colors.white,
129+
),
130+
),
131+
),
132+
],
133+
),
134+
),
135+
],
136+
),
137+
),
138+
),
139+
);
140+
},
141+
);
142+
} else if (snapshot.hasError) {
143+
return Text(snapshot.error.toString());
144+
}
145+
return Center(child: buildCircularProgressIndicator());
146+
},
38147
),
39-
);
148+
),
149+
],
150+
),
151+
);
40152
}
41153

42154
Widget _buildWidgetBackgroundCircle(MediaQueryData mediaQuery) {

0 commit comments

Comments
 (0)