Added season display to details screen.

pull/62/head
Andrew Brogdon 8 years ago
parent 673992f49e
commit 4445421332

@ -62,6 +62,13 @@ const Map<VeggieCategory, String> veggieCategoryNames = {
VeggieCategory.vegetable: 'Vegetable',
};
const Map<Season, String> seasonNames = {
Season.winter: 'Winter',
Season.spring: 'Spring',
Season.summer: 'Summer',
Season.autumn: 'Autumn',
};
class Veggie {
Veggie({
@required this.id,
@ -99,6 +106,27 @@ class Veggie {
/// Seasons during which a veggie is harvested.
final List<Season> seasons;
/// The same list of seasons, presented as a comma-separated list of strings
String get seasonsText {
if (seasons.length == 0) {
// '' (Shouldn't happen, but just in case)
return '';
} else if (seasons.length == 1) {
// 'Winter'
return seasonNames[seasons.first];
} else if (seasons.length == 2) {
// 'Winter and Spring'
return '${seasonNames[seasons.first]} and ${seasonNames[seasons[1]]}';
} else {
// 'Winter, Spring, and Autumn' (Oxford comma FTW)
String str = seasons
.sublist(0, seasons.length - 2)
.map((s) => seasonNames[s])
.join(', ');
return '$str, and ${seasonNames[seasons.last]}';
}
}
/// Percentage of the FDA's recommended daily value of vitamin A for someone
/// with a 2,000 calorie diet.
final int vitaminAPercentage;

@ -189,7 +189,18 @@ class InfoView extends StatelessWidget {
SizedBox(height: 8.0),
Text(
veggie.shortDescription,
style: Styles.detailsShortDescriptionText,
style: Styles.detailsDescriptionText,
),
SizedBox(height: 8.0),
Row(
children: <Widget>[
Text('Available in:', style: Styles.detailsBoldDescriptionText),
SizedBox(width: 4.0),
Text(
veggie.seasonsText,
style: Styles.detailsDescriptionText,
),
],
),
ServingInfoChart(veggie, prefs),
SizedBox(height: 24.0),

@ -87,7 +87,7 @@ abstract class Styles {
fontWeight: FontWeight.normal,
);
static const detailsShortDescriptionText = TextStyle(
static const detailsDescriptionText = TextStyle(
color: Color.fromRGBO(0, 0, 0, 0.9),
fontFamily: 'NotoSans',
fontSize: 16.0,
@ -95,6 +95,14 @@ abstract class Styles {
fontWeight: FontWeight.normal,
);
static const detailsBoldDescriptionText = TextStyle(
color: Color.fromRGBO(0, 0, 0, 0.9),
fontFamily: 'NotoSans',
fontSize: 16.0,
fontStyle: FontStyle.normal,
fontWeight: FontWeight.bold,
);
static const detailsServingHeaderText = TextStyle(
color: Color.fromRGBO(176, 176, 176, 1.0),
fontFamily: 'NotoSans',

Loading…
Cancel
Save