mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 13:58:47 +00:00
Adds season display to details screen. (#62)
This commit is contained in:
@@ -72,7 +72,7 @@ class LocalVeggieProvider {
|
||||
'2000 B.C.E.',
|
||||
'6500 B.C.E.',
|
||||
],
|
||||
1,
|
||||
2,
|
||||
),
|
||||
Trivia(
|
||||
'What are the seed pockets inside an apple called?',
|
||||
@@ -92,7 +92,7 @@ class LocalVeggieProvider {
|
||||
category: VeggieCategory.flower,
|
||||
shortDescription: 'The armadillo of vegetables.',
|
||||
accentColor: Color(0x408ea26d),
|
||||
seasons: [Season.autumn, Season.spring],
|
||||
seasons: [Season.spring, Season.autumn],
|
||||
vitaminAPercentage: 0,
|
||||
vitaminCPercentage: 25,
|
||||
servingSize: '1 medium artichoke',
|
||||
@@ -380,7 +380,7 @@ class LocalVeggieProvider {
|
||||
category: VeggieCategory.leafy,
|
||||
shortDescription: 'It\'s basically the veal of lettuce.',
|
||||
accentColor: Color(0x40c5be53),
|
||||
seasons: [Season.winter, Season.autumn, Season.spring],
|
||||
seasons: [Season.winter, Season.spring, Season.autumn],
|
||||
vitaminAPercentage: 10,
|
||||
vitaminCPercentage: 2,
|
||||
servingSize: '1/2 cup, chopped',
|
||||
@@ -422,7 +422,7 @@ class LocalVeggieProvider {
|
||||
category: VeggieCategory.fruit,
|
||||
shortDescription: 'Delicious when sliced and wrapped in prosciutto.',
|
||||
accentColor: Color(0x40aa6d7c),
|
||||
seasons: [Season.autumn, Season.summer],
|
||||
seasons: [Season.summer, Season.autumn],
|
||||
vitaminAPercentage: 2,
|
||||
vitaminCPercentage: 2,
|
||||
servingSize: '1 large fig',
|
||||
@@ -557,7 +557,7 @@ class LocalVeggieProvider {
|
||||
category: VeggieCategory.stealthFruit,
|
||||
shortDescription: 'Delicious... in extremely small quantities.',
|
||||
accentColor: Color(0x40ff7a01),
|
||||
seasons: [Season.autumn, Season.summer],
|
||||
seasons: [Season.summer, Season.autumn],
|
||||
vitaminAPercentage: 9,
|
||||
vitaminCPercentage: 100,
|
||||
servingSize: '1 pepper',
|
||||
@@ -1037,7 +1037,7 @@ class LocalVeggieProvider {
|
||||
category: VeggieCategory.leafy,
|
||||
shortDescription: 'It\'s that bitter taste in the salad you\'re eating.',
|
||||
accentColor: Color(0x40d75875),
|
||||
seasons: [Season.autumn, Season.spring],
|
||||
seasons: [Season.spring, Season.autumn],
|
||||
vitaminAPercentage: 0,
|
||||
vitaminCPercentage: 10,
|
||||
servingSize: '2 cups shredded',
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -164,22 +164,44 @@ class InfoView extends StatelessWidget {
|
||||
final prefs = ScopedModel.of<Preferences>(context, rebuildOnChange: true);
|
||||
final veggie = appState.getVeggie(id);
|
||||
|
||||
final seasonIcons = <Widget>[];
|
||||
|
||||
for (Season season in veggie.seasons) {
|
||||
seasonIcons.addAll([
|
||||
SizedBox(width: 12.0),
|
||||
Padding(
|
||||
padding: Styles.seasonIconPadding[season],
|
||||
child: Icon(
|
||||
Styles.seasonIconData[season],
|
||||
semanticLabel: seasonNames[season],
|
||||
color: Styles.seasonColors[season],
|
||||
),
|
||||
),
|
||||
]);
|
||||
}
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(24.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
FutureBuilder(
|
||||
future: prefs.preferredCategories,
|
||||
builder: (context, snapshot) {
|
||||
return Text(
|
||||
veggie.categoryName.toUpperCase(),
|
||||
style: (snapshot.hasData &&
|
||||
snapshot.data.contains(veggie.category))
|
||||
? Styles.detailsPreferredCategoryText
|
||||
: Styles.detailsCategoryText,
|
||||
);
|
||||
},
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: <Widget>[
|
||||
FutureBuilder(
|
||||
future: prefs.preferredCategories,
|
||||
builder: (context, snapshot) {
|
||||
return Text(
|
||||
veggie.categoryName.toUpperCase(),
|
||||
style: (snapshot.hasData &&
|
||||
snapshot.data.contains(veggie.category))
|
||||
? Styles.detailsPreferredCategoryText
|
||||
: Styles.detailsCategoryText,
|
||||
);
|
||||
},
|
||||
),
|
||||
Spacer(),
|
||||
]..addAll(seasonIcons),
|
||||
),
|
||||
SizedBox(height: 8.0),
|
||||
Text(
|
||||
@@ -189,7 +211,7 @@ class InfoView extends StatelessWidget {
|
||||
SizedBox(height: 8.0),
|
||||
Text(
|
||||
veggie.shortDescription,
|
||||
style: Styles.detailsShortDescriptionText,
|
||||
style: Styles.detailsDescriptionText,
|
||||
),
|
||||
ServingInfoChart(veggie, prefs),
|
||||
SizedBox(height: 24.0),
|
||||
@@ -261,22 +283,28 @@ class _DetailsScreenState extends State<DetailsScreen> {
|
||||
return CupertinoPageScaffold(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_buildHeader(context, appState),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 16.0),
|
||||
child: CupertinoSegmentedControl(
|
||||
children: {
|
||||
0: Text('Facts & Info'),
|
||||
1: Text('Trivia'),
|
||||
},
|
||||
groupValue: _selectedViewIndex,
|
||||
onValueChanged: (value) {
|
||||
setState(() => _selectedViewIndex = value);
|
||||
},
|
||||
Expanded(
|
||||
child: ListView(
|
||||
children: [
|
||||
CupertinoSegmentedControl(
|
||||
children: {
|
||||
0: Text('Facts & Info'),
|
||||
1: Text('Trivia'),
|
||||
},
|
||||
groupValue: _selectedViewIndex,
|
||||
onValueChanged: (value) {
|
||||
setState(() => _selectedViewIndex = value);
|
||||
},
|
||||
),
|
||||
_selectedViewIndex == 0
|
||||
? InfoView(widget.id)
|
||||
: TriviaView(widget.id),
|
||||
],
|
||||
),
|
||||
),
|
||||
_selectedViewIndex == 0 ? InfoView(widget.id) : TriviaView(widget.id),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:veggieseasons/data/veggie.dart';
|
||||
|
||||
abstract class Styles {
|
||||
@@ -87,7 +88,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 +96,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',
|
||||
@@ -182,6 +191,22 @@ abstract class Styles {
|
||||
Season.autumn: Color(0xff724913),
|
||||
};
|
||||
|
||||
// While handy, some of the Font Awesome icons sometimes bleed over their
|
||||
// allotted bounds. This padding is used to adjust for that.
|
||||
static const seasonIconPadding = {
|
||||
Season.winter: const EdgeInsets.only(right: 0.0),
|
||||
Season.spring: const EdgeInsets.only(right: 4.0),
|
||||
Season.summer: const EdgeInsets.only(right: 6.0),
|
||||
Season.autumn: const EdgeInsets.only(right: 0.0),
|
||||
};
|
||||
|
||||
static const seasonIconData = {
|
||||
Season.winter: FontAwesomeIcons.snowflake,
|
||||
Season.spring: FontAwesomeIcons.leaf,
|
||||
Season.summer: FontAwesomeIcons.umbrellaBeach,
|
||||
Season.autumn: FontAwesomeIcons.canadianMapleLeaf,
|
||||
};
|
||||
|
||||
static const seasonBorder = Border(
|
||||
top: BorderSide(color: Color(0xff606060)),
|
||||
left: BorderSide(color: Color(0xff606060)),
|
||||
|
||||
Reference in New Issue
Block a user