Skip to content

Commit 91eefb2

Browse files
committed
Buat class utils untuk menampung fungsi-fungsi utilitas yang reusable
1 parent 8bded24 commit 91eefb2

File tree

2 files changed

+56
-42
lines changed

2 files changed

+56
-42
lines changed

lib/src/ui/home/home_screen.dart

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
import 'dart:io' show Platform;
2-
31
import 'package:flutter/cupertino.dart';
42
import 'package:flutter/material.dart';
53
import 'package:food_recipe/src/blocs/home_bloc.dart';
64
import 'package:food_recipe/src/models/categories/categories.dart';
75
import 'package:food_recipe/src/models/latest/latest_meals.dart';
6+
import 'package:food_recipe/src/utils/utils.dart';
87
import 'package:food_recipe/values/color_assets.dart';
98

109
class HomeScreen extends StatefulWidget {
@@ -13,8 +12,6 @@ class HomeScreen extends StatefulWidget {
1312
}
1413

1514
class _HomeScreenState extends State<HomeScreen> {
16-
String result = "-";
17-
1815
@override
1916
void dispose() {
2017
homeBloc.dispose();
@@ -26,7 +23,11 @@ class _HomeScreenState extends State<HomeScreen> {
2623
return Stack(
2724
children: <Widget>[
2825
_buildWidgetBackground(),
29-
_buildWidgetContent(),
26+
ListView(
27+
children: <Widget>[
28+
_buildWidgetContent(),
29+
],
30+
),
3031
],
3132
);
3233
}
@@ -35,6 +36,7 @@ class _HomeScreenState extends State<HomeScreen> {
3536
return Column(
3637
children: <Widget>[
3738
Expanded(
39+
flex: 2,
3840
child: Container(
3941
color: ColorAssets.primarySwatchColor,
4042
),
@@ -111,34 +113,41 @@ class _HomeScreenState extends State<HomeScreen> {
111113
width: 136.0,
112114
child: Padding(
113115
padding: const EdgeInsets.only(right: 4.0),
114-
child: Card(
115-
shape: RoundedRectangleBorder(
116-
borderRadius: BorderRadius.circular(16.0)),
117-
color: _setColorItemCategory(numberItem),
118-
child: Padding(
119-
padding: const EdgeInsets.symmetric(horizontal: 8.0, vertical: 12.0),
120-
child: Column(
121-
children: <Widget>[
122-
Text(
123-
category.strCategory,
124-
textAlign: TextAlign.center,
125-
style: TextStyle(
126-
color: Colors.white,
116+
child: GestureDetector(
117+
onTap: () {
118+
// TODO: do something in here
119+
},
120+
child: Card(
121+
shape: RoundedRectangleBorder(
122+
borderRadius: BorderRadius.circular(16.0)),
123+
color: _setColorItemCategory(numberItem),
124+
child: Padding(
125+
padding: const EdgeInsets.symmetric(
126+
horizontal: 8.0, vertical: 12.0),
127+
child: Column(
128+
children: <Widget>[
129+
Text(
130+
category.strCategory,
131+
textAlign: TextAlign.center,
132+
style: TextStyle(
133+
color: Colors.white,
134+
),
127135
),
128-
),
129-
Padding(padding: const EdgeInsets.only(top: 8.0)),
130-
Container(
131-
width: 136.0,
132-
height: 72.0,
133-
child: FadeInImage(
134-
fit: BoxFit.cover,
135-
image: NetworkImage(
136-
category.strCategoryThumb,
136+
Padding(padding: const EdgeInsets.only(top: 8.0)),
137+
Container(
138+
width: 136.0,
139+
height: 72.0,
140+
child: FadeInImage(
141+
fit: BoxFit.cover,
142+
image: NetworkImage(
143+
category.strCategoryThumb,
144+
),
145+
placeholder: AssetImage(
146+
"assets/images/img_placeholder.jpg"),
137147
),
138-
placeholder: AssetImage("assets/images/img_placeholder.jpg"),
139148
),
140-
),
141-
],
149+
],
150+
),
142151
),
143152
),
144153
),
@@ -150,7 +159,7 @@ class _HomeScreenState extends State<HomeScreen> {
150159
} else if (snapshot.hasError) {
151160
return Text(snapshot.error.toString());
152161
}
153-
return Center(child: _buildCircularProgressIndicator());
162+
return Center(child: buildCircularProgressIndicator());
154163
},
155164
);
156165
}
@@ -162,7 +171,7 @@ class _HomeScreenState extends State<HomeScreen> {
162171
if (snapshot.hasData) {
163172
var latestMeals = snapshot.data;
164173
return Container(
165-
height: 256.0,
174+
height: mediaQuery.size.width / 2 + 64.0, // 256.0
166175
child: ListView.builder(
167176
scrollDirection: Axis.horizontal,
168177
itemCount: latestMeals.latestMealsItems.length,
@@ -171,6 +180,7 @@ class _HomeScreenState extends State<HomeScreen> {
171180
return Padding(
172181
padding: const EdgeInsets.only(right: 8.0),
173182
child: Card(
183+
elevation: 4.0,
174184
shape: RoundedRectangleBorder(
175185
borderRadius: BorderRadius.circular(16.0)),
176186
child: ClipRRect(
@@ -192,7 +202,7 @@ class _HomeScreenState extends State<HomeScreen> {
192202
fit: BoxFit.cover,
193203
),
194204
width: mediaQuery.size.width - 96.0,
195-
height: 192.0,
205+
height: mediaQuery.size.width / 2, // 192.0
196206
),
197207
Padding(
198208
padding: const EdgeInsets.all(8.0),
@@ -214,7 +224,7 @@ class _HomeScreenState extends State<HomeScreen> {
214224
return Container(
215225
height: 128.0,
216226
child: Center(
217-
child: _buildCircularProgressIndicator(),
227+
child: buildCircularProgressIndicator(),
218228
),
219229
);
220230
},
@@ -257,14 +267,6 @@ class _HomeScreenState extends State<HomeScreen> {
257267
);
258268
}
259269

260-
Widget _buildCircularProgressIndicator() {
261-
if (Platform.isIOS) {
262-
return CupertinoActivityIndicator();
263-
} else {
264-
return CircularProgressIndicator();
265-
}
266-
}
267-
268270
Color _setColorItemCategory(int number) {
269271
if (number == 1) {
270272
return ColorAssets.accentColor;

lib/src/utils/utils.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import 'dart:io' show Platform;
2+
3+
import 'package:flutter/cupertino.dart';
4+
import 'package:flutter/material.dart';
5+
6+
Widget buildCircularProgressIndicator() {
7+
if (Platform.isIOS) {
8+
return CupertinoActivityIndicator();
9+
} else {
10+
return CircularProgressIndicator();
11+
}
12+
}

0 commit comments

Comments
 (0)