mirror of
https://github.com/flutter/samples.git
synced 2026-06-07 14:59:43 +00:00
Adds veggieseasons preferences, tweaks styles + list page (#37)
This commit is contained in:
@@ -9,13 +9,19 @@ import 'package:veggieseasons/data/model.dart';
|
||||
import 'package:veggieseasons/data/veggie.dart';
|
||||
import 'package:veggieseasons/styles.dart';
|
||||
|
||||
/// A circular widget that indicates in which seasons a particular veggie can be
|
||||
/// harvested. It displays the first two letters of the season and uses a
|
||||
/// different background color to represent each of the seasons as well.
|
||||
/// A circular widget that represents a season of the year.
|
||||
///
|
||||
/// The season can be displayed as a valid harvest season or one during which a
|
||||
/// particular veggie cannot be harvested. Bright colors are used in the first
|
||||
/// case, and grays in the latter.
|
||||
class SeasonCircle extends StatelessWidget {
|
||||
SeasonCircle(this.season, this.isHarvestTime);
|
||||
|
||||
/// Season to be displayed by this widget.
|
||||
final Season season;
|
||||
|
||||
SeasonCircle(this.season);
|
||||
/// Whether or not [season] should be presented as a valid harvest season.
|
||||
final bool isHarvestTime;
|
||||
|
||||
String get _firstChars {
|
||||
return '${season.toString().substring(7, 8).toUpperCase()}'
|
||||
@@ -28,7 +34,9 @@ class SeasonCircle extends StatelessWidget {
|
||||
padding: const EdgeInsets.all(4.0),
|
||||
child: DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: Styles.seasonColors[season],
|
||||
color: isHarvestTime
|
||||
? Styles.seasonColors[season]
|
||||
: Styles.transparentColor,
|
||||
borderRadius: BorderRadius.circular(25.0),
|
||||
border: Styles.seasonBorder,
|
||||
),
|
||||
@@ -36,7 +44,12 @@ class SeasonCircle extends StatelessWidget {
|
||||
height: 50.0,
|
||||
width: 50.0,
|
||||
child: Center(
|
||||
child: Text(_firstChars, style: Styles.seasonText),
|
||||
child: Text(
|
||||
_firstChars,
|
||||
style: isHarvestTime
|
||||
? Styles.activeSeasonText
|
||||
: Styles.inactiveSeasonText,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -116,8 +129,9 @@ class DetailsScreen extends StatelessWidget {
|
||||
mainAxisSize: MainAxisSize.max,
|
||||
children: [
|
||||
Wrap(
|
||||
children:
|
||||
veggie.seasons.map<Widget>((s) => SeasonCircle(s)).toList(),
|
||||
children: Season.values.map((s) {
|
||||
return SeasonCircle(s, veggie.seasons.contains(s));
|
||||
}).toList(),
|
||||
),
|
||||
SizedBox(width: 8.0),
|
||||
Expanded(
|
||||
|
||||
@@ -27,42 +27,44 @@ class ListScreen extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
String dateString = DateFormat.yMMMMd("en_US").format(DateTime.now());
|
||||
final model = ScopedModel.of<AppState>(context, rebuildOnChange: true);
|
||||
|
||||
final rows = <Widget>[];
|
||||
|
||||
rows.add(
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16.0, 24.0, 16.0, 16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(dateString.toUpperCase(), style: Styles.minorText),
|
||||
Text('In season today', style: Styles.headlineText),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
rows.addAll(_generateVeggieRows(model.availableVeggies));
|
||||
|
||||
rows.add(
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16.0, 24.0, 16.0, 16.0),
|
||||
child: Text('Not in season', style: Styles.headlineText),
|
||||
),
|
||||
);
|
||||
|
||||
rows.addAll(_generateVeggieRows(model.unavailableVeggies));
|
||||
|
||||
return CupertinoTabView(
|
||||
builder: (context) => DecoratedBox(
|
||||
decoration: BoxDecoration(color: Color(0xffffffff)),
|
||||
child: ListView(
|
||||
children: rows,
|
||||
builder: (context) {
|
||||
String dateString = DateFormat.yMMMMd("en_US").format(DateTime.now());
|
||||
final model = ScopedModel.of<AppState>(context, rebuildOnChange: true);
|
||||
|
||||
final rows = <Widget>[];
|
||||
|
||||
rows.add(
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16.0, 24.0, 16.0, 16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(dateString.toUpperCase(), style: Styles.minorText),
|
||||
Text('In season today', style: Styles.headlineText),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
rows.addAll(_generateVeggieRows(model.availableVeggies));
|
||||
|
||||
rows.add(
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16.0, 24.0, 16.0, 16.0),
|
||||
child: Text('Not in season', style: Styles.headlineText),
|
||||
),
|
||||
);
|
||||
|
||||
rows.addAll(_generateVeggieRows(model.unavailableVeggies));
|
||||
|
||||
return DecoratedBox(
|
||||
decoration: BoxDecoration(color: Color(0xffffffff)),
|
||||
child: ListView(
|
||||
children: rows,
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user