Skip to content

Commit 08beb69

Browse files
authored
Updates veggieseasons to Dart 2.3, adds some minor UI updates (#88)
1 parent cf2a3b2 commit 08beb69

18 files changed

+348
-325
lines changed

veggieseasons/ios/Podfile.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ SPEC CHECKSUMS:
1717
Flutter: 58dd7d1b27887414a370fcccb9e645c08ffd7a6a
1818
shared_preferences: 1feebfa37bb57264736e16865e7ffae7fc99b523
1919

20-
PODFILE CHECKSUM: aff02bfeed411c636180d6812254b2daeea14d09
20+
PODFILE CHECKSUM: e8988baac3a50f787b9d3ed7ca44957b442f92a7
2121

22-
COCOAPODS: 1.6.1
22+
COCOAPODS: 1.7.0

veggieseasons/ios/Runner.xcodeproj/project.pbxproj

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
5757
97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
5858
97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
59+
9AC24389CA19ECD679B522EE /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = "<group>"; };
5960
BA0A9C772FFC1878911ECDBC /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; };
6061
/* End PBXFileReference section */
6162

@@ -134,6 +135,7 @@
134135
children = (
135136
BA0A9C772FFC1878911ECDBC /* Pods-Runner.debug.xcconfig */,
136137
44D0F7D543E9A9D5B9AF94AC /* Pods-Runner.release.xcconfig */,
138+
9AC24389CA19ECD679B522EE /* Pods-Runner.profile.xcconfig */,
137139
);
138140
name = Pods;
139141
sourceTree = "<group>";

veggieseasons/lib/data/local_veggie_provider.dart

+18
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,15 @@ class LocalVeggieProvider {
227227
],
228228
1,
229229
),
230+
Trivia(
231+
'The first evidence of avocado consumption by humans dates back to what year?',
232+
[
233+
'2,000 B.C.',
234+
'6,000 B.C.',
235+
'10,000 B.C.',
236+
],
237+
2,
238+
),
230239
],
231240
),
232241
Veggie(
@@ -371,6 +380,15 @@ class LocalVeggieProvider {
371380
],
372381
0,
373382
),
383+
Trivia(
384+
'Green cauliflower is sometimes called what?',
385+
[
386+
'Broccoflower',
387+
'Avocadoflower',
388+
'Gross',
389+
],
390+
0,
391+
),
374392
],
375393
),
376394
Veggie(

veggieseasons/lib/screens/details.dart

+27-32
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ class ServingInfoChart extends StatelessWidget {
4242
Widget build(BuildContext context) {
4343
return Column(
4444
children: [
45-
SizedBox(height: 16.0),
45+
SizedBox(height: 16),
4646
Align(
4747
alignment: Alignment.centerLeft,
4848
child: Padding(
4949
padding: const EdgeInsets.only(
50-
left: 9.0,
51-
bottom: 4.0,
50+
left: 9,
51+
bottom: 4,
5252
),
5353
child: Text(
5454
'Serving info',
@@ -60,7 +60,7 @@ class ServingInfoChart extends StatelessWidget {
6060
decoration: BoxDecoration(
6161
border: Border.all(color: Styles.servingInfoBorderColor),
6262
),
63-
padding: const EdgeInsets.all(8.0),
63+
padding: const EdgeInsets.all(8),
6464
child: Column(
6565
children: [
6666
Table(
@@ -134,7 +134,7 @@ class ServingInfoChart extends StatelessWidget {
134134
],
135135
),
136136
Padding(
137-
padding: const EdgeInsets.only(top: 16.0),
137+
padding: const EdgeInsets.only(top: 16),
138138
child: FutureBuilder(
139139
future: prefs.desiredCalories,
140140
builder: (context, snapshot) {
@@ -164,24 +164,8 @@ class InfoView extends StatelessWidget {
164164
final prefs = ScopedModel.of<Preferences>(context, rebuildOnChange: true);
165165
final veggie = appState.getVeggie(id);
166166

167-
final seasonIcons = <Widget>[];
168-
169-
for (Season season in veggie.seasons) {
170-
seasonIcons.addAll([
171-
SizedBox(width: 12.0),
172-
Padding(
173-
padding: Styles.seasonIconPadding[season],
174-
child: Icon(
175-
Styles.seasonIconData[season],
176-
semanticLabel: seasonNames[season],
177-
color: Styles.seasonColors[season],
178-
),
179-
),
180-
]);
181-
}
182-
183167
return Padding(
184-
padding: const EdgeInsets.all(24.0),
168+
padding: const EdgeInsets.all(24),
185169
child: Column(
186170
crossAxisAlignment: CrossAxisAlignment.stretch,
187171
children: [
@@ -201,20 +185,31 @@ class InfoView extends StatelessWidget {
201185
},
202186
),
203187
Spacer(),
204-
]..addAll(seasonIcons),
188+
for (Season season in veggie.seasons) ...[
189+
SizedBox(width: 12),
190+
Padding(
191+
padding: Styles.seasonIconPadding[season],
192+
child: Icon(
193+
Styles.seasonIconData[season],
194+
semanticLabel: seasonNames[season],
195+
color: Styles.seasonColors[season],
196+
),
197+
),
198+
],
199+
],
205200
),
206-
SizedBox(height: 8.0),
201+
SizedBox(height: 8),
207202
Text(
208203
veggie.name,
209204
style: Styles.detailsTitleText,
210205
),
211-
SizedBox(height: 8.0),
206+
SizedBox(height: 8),
212207
Text(
213208
veggie.shortDescription,
214209
style: Styles.detailsDescriptionText,
215210
),
216211
ServingInfoChart(veggie, prefs),
217-
SizedBox(height: 24.0),
212+
SizedBox(height: 24),
218213
Row(
219214
mainAxisSize: MainAxisSize.min,
220215
children: [
@@ -224,7 +219,7 @@ class InfoView extends StatelessWidget {
224219
appState.setFavorite(id, value);
225220
},
226221
),
227-
SizedBox(width: 8.0),
222+
SizedBox(width: 8),
228223
Text('Save to Garden'),
229224
],
230225
),
@@ -250,21 +245,21 @@ class _DetailsScreenState extends State<DetailsScreen> {
250245
final veggie = model.getVeggie(widget.id);
251246

252247
return SizedBox(
253-
height: 150.0,
248+
height: 150,
254249
child: Stack(
255250
children: [
256251
Positioned(
257-
right: 0.0,
258-
left: 0.0,
252+
right: 0,
253+
left: 0,
259254
child: Image.asset(
260255
veggie.imageAssetPath,
261256
fit: BoxFit.cover,
262257
semanticLabel: 'A background image of ${veggie.name}',
263258
),
264259
),
265260
Positioned(
266-
top: 16.0,
267-
left: 16.0,
261+
top: 16,
262+
left: 16,
268263
child: SafeArea(
269264
child: CloseButton(() {
270265
Navigator.of(context).pop();

veggieseasons/lib/screens/favorites.dart

+20-34
Original file line numberDiff line numberDiff line change
@@ -11,49 +11,35 @@ import 'package:veggieseasons/styles.dart';
1111
import 'package:veggieseasons/widgets/veggie_headline.dart';
1212

1313
class FavoritesScreen extends StatelessWidget {
14-
/// Builds the "content" of the favorites screen: either a list of favorite
15-
/// veggies or a note that says the user hasn't favorited any yet.
16-
Widget _buildTabViewBody(BuildContext context) {
17-
final model = ScopedModel.of<AppState>(context, rebuildOnChange: true);
18-
19-
if (model.favoriteVeggies.length == 0) {
20-
return Padding(
21-
padding: const EdgeInsets.symmetric(horizontal: 24.0),
22-
child: Text(
23-
'You haven\'t added any favorite veggies to your garden yet.',
24-
style: Styles.headlineDescription,
25-
),
26-
);
27-
}
28-
29-
final rows = <Widget>[
30-
SizedBox(height: 24.0),
31-
];
32-
33-
for (Veggie veggie in model.favoriteVeggies) {
34-
rows.add(
35-
Padding(
36-
padding: EdgeInsets.only(left: 16.0, right: 16.0, bottom: 24.0),
37-
child: VeggieHeadline(veggie),
38-
),
39-
);
40-
}
41-
42-
return ListView(
43-
children: rows,
44-
);
45-
}
46-
4714
@override
4815
Widget build(BuildContext context) {
4916
return CupertinoTabView(
5017
builder: (context) {
18+
final model = ScopedModel.of<AppState>(context, rebuildOnChange: true);
19+
5120
return CupertinoPageScaffold(
5221
navigationBar: CupertinoNavigationBar(
5322
middle: Text('My Garden'),
5423
),
5524
child: Center(
56-
child: _buildTabViewBody(context),
25+
child: model.favoriteVeggies.isEmpty
26+
? Padding(
27+
padding: const EdgeInsets.symmetric(horizontal: 24),
28+
child: Text(
29+
'You haven\'t added any favorite veggies to your garden yet.',
30+
style: Styles.headlineDescription,
31+
),
32+
)
33+
: ListView(
34+
children: [
35+
SizedBox(height: 24),
36+
for (Veggie veggie in model.favoriteVeggies)
37+
Padding(
38+
padding: EdgeInsets.fromLTRB(16, 0, 16, 24),
39+
child: VeggieHeadline(veggie),
40+
),
41+
],
42+
),
5743
),
5844
);
5945
},

veggieseasons/lib/screens/list.dart

+43-47
Original file line numberDiff line numberDiff line change
@@ -13,67 +13,63 @@ import 'package:veggieseasons/styles.dart';
1313
import 'package:veggieseasons/widgets/veggie_card.dart';
1414

1515
class ListScreen extends StatelessWidget {
16-
List<Widget> _generateVeggieRows(List<Veggie> veggies, Preferences prefs,
17-
{bool inSeason = true}) {
18-
final cards = List<Widget>();
19-
20-
for (Veggie veggie in veggies) {
21-
cards.add(Padding(
22-
padding: EdgeInsets.only(left: 16.0, right: 16.0, bottom: 24.0),
23-
child: FutureBuilder<Set<VeggieCategory>>(
24-
future: prefs.preferredCategories,
25-
builder: (context, snapshot) {
26-
final data = snapshot.data ?? Set<VeggieCategory>();
27-
return VeggieCard(
28-
veggie, inSeason, data.contains(veggie.category));
29-
}),
30-
));
31-
}
32-
33-
return cards;
16+
Widget _generateVeggieRow(veggie, Preferences prefs, {bool inSeason = true}) {
17+
return Padding(
18+
padding: EdgeInsets.only(left: 16, right: 16, bottom: 24),
19+
child: FutureBuilder<Set<VeggieCategory>>(
20+
future: prefs.preferredCategories,
21+
builder: (context, snapshot) {
22+
final data = snapshot.data ?? Set<VeggieCategory>();
23+
return VeggieCard(veggie, inSeason, data.contains(veggie.category));
24+
}),
25+
);
3426
}
3527

3628
@override
3729
Widget build(BuildContext context) {
3830
return CupertinoTabView(
3931
builder: (context) {
4032
String dateString = DateFormat("MMMM y").format(DateTime.now());
33+
4134
final appState =
4235
ScopedModel.of<AppState>(context, rebuildOnChange: true);
4336
final prefs =
4437
ScopedModel.of<Preferences>(context, rebuildOnChange: true);
4538

46-
final rows = <Widget>[];
47-
48-
rows.add(
49-
Padding(
50-
padding: const EdgeInsets.fromLTRB(16.0, 24.0, 16.0, 16.0),
51-
child: Column(
52-
crossAxisAlignment: CrossAxisAlignment.start,
53-
children: [
54-
Text(dateString.toUpperCase(), style: Styles.minorText),
55-
Text('In season today', style: Styles.headlineText),
56-
],
57-
),
58-
),
59-
);
60-
61-
rows.addAll(_generateVeggieRows(appState.availableVeggies, prefs));
62-
63-
rows.add(
64-
Padding(
65-
padding: const EdgeInsets.fromLTRB(16.0, 24.0, 16.0, 16.0),
66-
child: Text('Not in season', style: Styles.headlineText),
67-
),
68-
);
69-
70-
rows.addAll(_generateVeggieRows(appState.unavailableVeggies, prefs,
71-
inSeason: false));
72-
7339
return DecoratedBox(
7440
decoration: BoxDecoration(color: Color(0xffffffff)),
75-
child: ListView(
76-
children: rows,
41+
child: ListView.builder(
42+
itemCount: appState.allVeggies.length + 2,
43+
itemBuilder: (context, index) {
44+
if (index == 0) {
45+
return Padding(
46+
padding: const EdgeInsets.fromLTRB(16, 24, 16, 16),
47+
child: Column(
48+
crossAxisAlignment: CrossAxisAlignment.start,
49+
children: [
50+
Text(dateString.toUpperCase(), style: Styles.minorText),
51+
Text('In season today', style: Styles.headlineText),
52+
],
53+
),
54+
);
55+
} else if (index <= appState.availableVeggies.length) {
56+
return _generateVeggieRow(
57+
appState.availableVeggies[index - 1],
58+
prefs,
59+
);
60+
} else if (index <= appState.availableVeggies.length + 1) {
61+
return Padding(
62+
padding: const EdgeInsets.fromLTRB(16, 24, 16, 16),
63+
child: Text('Not in season', style: Styles.headlineText),
64+
);
65+
} else {
66+
int relativeIndex =
67+
index - (appState.availableVeggies.length + 2);
68+
return _generateVeggieRow(
69+
appState.unavailableVeggies[relativeIndex], prefs,
70+
inSeason: false);
71+
}
72+
},
7773
),
7874
);
7975
},

veggieseasons/lib/screens/search.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class _SearchScreenState extends State<SearchScreen> {
3939

4040
Widget _createSearchBox() {
4141
return Padding(
42-
padding: const EdgeInsets.all(8.0),
42+
padding: const EdgeInsets.all(8),
4343
child: SearchBar(
4444
controller: controller,
4545
focusNode: focusNode,
@@ -51,7 +51,7 @@ class _SearchScreenState extends State<SearchScreen> {
5151
if (veggies.isEmpty) {
5252
return Center(
5353
child: Padding(
54-
padding: const EdgeInsets.symmetric(horizontal: 24.0),
54+
padding: const EdgeInsets.symmetric(horizontal: 24),
5555
child: Text(
5656
'No veggies matching your search terms were found.',
5757
style: Styles.headlineDescription,
@@ -64,7 +64,7 @@ class _SearchScreenState extends State<SearchScreen> {
6464
itemCount: veggies.length,
6565
itemBuilder: (context, i) {
6666
return Padding(
67-
padding: EdgeInsets.only(left: 16.0, right: 16.0, bottom: 24.0),
67+
padding: EdgeInsets.only(left: 16, right: 16, bottom: 24),
6868
child: VeggieHeadline(veggies[i]),
6969
);
7070
},

0 commit comments

Comments
 (0)