From bf3a963bdc66ef0e4d47aca2827c9bfb6e0c909c Mon Sep 17 00:00:00 2001 From: Andrew Brogdon Date: Mon, 25 Mar 2019 11:22:23 -0700 Subject: [PATCH] Adds season display to details screen. (#62) --- .../lib/data/local_veggie_provider.dart | 12 +-- veggieseasons/lib/data/veggie.dart | 7 ++ veggieseasons/lib/screens/details.dart | 76 +++++++++++++------ veggieseasons/lib/styles.dart | 27 ++++++- veggieseasons/pubspec.yaml | 1 + 5 files changed, 92 insertions(+), 31 deletions(-) diff --git a/veggieseasons/lib/data/local_veggie_provider.dart b/veggieseasons/lib/data/local_veggie_provider.dart index 8e3cb2a2a..1567e949e 100644 --- a/veggieseasons/lib/data/local_veggie_provider.dart +++ b/veggieseasons/lib/data/local_veggie_provider.dart @@ -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', diff --git a/veggieseasons/lib/data/veggie.dart b/veggieseasons/lib/data/veggie.dart index 48e2d6af3..3161a6534 100644 --- a/veggieseasons/lib/data/veggie.dart +++ b/veggieseasons/lib/data/veggie.dart @@ -62,6 +62,13 @@ const Map veggieCategoryNames = { VeggieCategory.vegetable: 'Vegetable', }; +const Map seasonNames = { + Season.winter: 'Winter', + Season.spring: 'Spring', + Season.summer: 'Summer', + Season.autumn: 'Autumn', +}; + class Veggie { Veggie({ @required this.id, diff --git a/veggieseasons/lib/screens/details.dart b/veggieseasons/lib/screens/details.dart index 49b8a3838..5f63199fa 100644 --- a/veggieseasons/lib/screens/details.dart +++ b/veggieseasons/lib/screens/details.dart @@ -164,22 +164,44 @@ class InfoView extends StatelessWidget { final prefs = ScopedModel.of(context, rebuildOnChange: true); final veggie = appState.getVeggie(id); + final seasonIcons = []; + + 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: [ + 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 { 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), ], ), ); diff --git a/veggieseasons/lib/styles.dart b/veggieseasons/lib/styles.dart index dc004f3de..e2017f066 100644 --- a/veggieseasons/lib/styles.dart +++ b/veggieseasons/lib/styles.dart @@ -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)), diff --git a/veggieseasons/pubspec.yaml b/veggieseasons/pubspec.yaml index 13e226d01..b1b576b04 100644 --- a/veggieseasons/pubspec.yaml +++ b/veggieseasons/pubspec.yaml @@ -11,6 +11,7 @@ dependencies: sdk: flutter cupertino_icons: ^0.1.2 + font_awesome_flutter: ^8.4.0 intl: ^0.15.7 scoped_model: ^1.0.1 shared_preferences: ^0.4.3