mirror of
https://github.com/flutter/samples.git
synced 2025-11-10 14:58:34 +00:00
Updates veggieseasons to Dart 2.3, adds some minor UI updates (#88)
This commit is contained in:
@@ -42,13 +42,13 @@ class ServingInfoChart extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
SizedBox(height: 16.0),
|
||||
SizedBox(height: 16),
|
||||
Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
left: 9.0,
|
||||
bottom: 4.0,
|
||||
left: 9,
|
||||
bottom: 4,
|
||||
),
|
||||
child: Text(
|
||||
'Serving info',
|
||||
@@ -60,7 +60,7 @@ class ServingInfoChart extends StatelessWidget {
|
||||
decoration: BoxDecoration(
|
||||
border: Border.all(color: Styles.servingInfoBorderColor),
|
||||
),
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: Column(
|
||||
children: [
|
||||
Table(
|
||||
@@ -134,7 +134,7 @@ class ServingInfoChart extends StatelessWidget {
|
||||
],
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 16.0),
|
||||
padding: const EdgeInsets.only(top: 16),
|
||||
child: FutureBuilder(
|
||||
future: prefs.desiredCalories,
|
||||
builder: (context, snapshot) {
|
||||
@@ -164,24 +164,8 @@ 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),
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
@@ -201,20 +185,31 @@ class InfoView extends StatelessWidget {
|
||||
},
|
||||
),
|
||||
Spacer(),
|
||||
]..addAll(seasonIcons),
|
||||
for (Season season in veggie.seasons) ...[
|
||||
SizedBox(width: 12),
|
||||
Padding(
|
||||
padding: Styles.seasonIconPadding[season],
|
||||
child: Icon(
|
||||
Styles.seasonIconData[season],
|
||||
semanticLabel: seasonNames[season],
|
||||
color: Styles.seasonColors[season],
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
SizedBox(height: 8.0),
|
||||
SizedBox(height: 8),
|
||||
Text(
|
||||
veggie.name,
|
||||
style: Styles.detailsTitleText,
|
||||
),
|
||||
SizedBox(height: 8.0),
|
||||
SizedBox(height: 8),
|
||||
Text(
|
||||
veggie.shortDescription,
|
||||
style: Styles.detailsDescriptionText,
|
||||
),
|
||||
ServingInfoChart(veggie, prefs),
|
||||
SizedBox(height: 24.0),
|
||||
SizedBox(height: 24),
|
||||
Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
@@ -224,7 +219,7 @@ class InfoView extends StatelessWidget {
|
||||
appState.setFavorite(id, value);
|
||||
},
|
||||
),
|
||||
SizedBox(width: 8.0),
|
||||
SizedBox(width: 8),
|
||||
Text('Save to Garden'),
|
||||
],
|
||||
),
|
||||
@@ -250,12 +245,12 @@ class _DetailsScreenState extends State<DetailsScreen> {
|
||||
final veggie = model.getVeggie(widget.id);
|
||||
|
||||
return SizedBox(
|
||||
height: 150.0,
|
||||
height: 150,
|
||||
child: Stack(
|
||||
children: [
|
||||
Positioned(
|
||||
right: 0.0,
|
||||
left: 0.0,
|
||||
right: 0,
|
||||
left: 0,
|
||||
child: Image.asset(
|
||||
veggie.imageAssetPath,
|
||||
fit: BoxFit.cover,
|
||||
@@ -263,8 +258,8 @@ class _DetailsScreenState extends State<DetailsScreen> {
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
top: 16.0,
|
||||
left: 16.0,
|
||||
top: 16,
|
||||
left: 16,
|
||||
child: SafeArea(
|
||||
child: CloseButton(() {
|
||||
Navigator.of(context).pop();
|
||||
|
||||
@@ -11,49 +11,35 @@ import 'package:veggieseasons/styles.dart';
|
||||
import 'package:veggieseasons/widgets/veggie_headline.dart';
|
||||
|
||||
class FavoritesScreen extends StatelessWidget {
|
||||
/// Builds the "content" of the favorites screen: either a list of favorite
|
||||
/// veggies or a note that says the user hasn't favorited any yet.
|
||||
Widget _buildTabViewBody(BuildContext context) {
|
||||
final model = ScopedModel.of<AppState>(context, rebuildOnChange: true);
|
||||
|
||||
if (model.favoriteVeggies.length == 0) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24.0),
|
||||
child: Text(
|
||||
'You haven\'t added any favorite veggies to your garden yet.',
|
||||
style: Styles.headlineDescription,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
final rows = <Widget>[
|
||||
SizedBox(height: 24.0),
|
||||
];
|
||||
|
||||
for (Veggie veggie in model.favoriteVeggies) {
|
||||
rows.add(
|
||||
Padding(
|
||||
padding: EdgeInsets.only(left: 16.0, right: 16.0, bottom: 24.0),
|
||||
child: VeggieHeadline(veggie),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return ListView(
|
||||
children: rows,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return CupertinoTabView(
|
||||
builder: (context) {
|
||||
final model = ScopedModel.of<AppState>(context, rebuildOnChange: true);
|
||||
|
||||
return CupertinoPageScaffold(
|
||||
navigationBar: CupertinoNavigationBar(
|
||||
middle: Text('My Garden'),
|
||||
),
|
||||
child: Center(
|
||||
child: _buildTabViewBody(context),
|
||||
child: model.favoriteVeggies.isEmpty
|
||||
? Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
child: Text(
|
||||
'You haven\'t added any favorite veggies to your garden yet.',
|
||||
style: Styles.headlineDescription,
|
||||
),
|
||||
)
|
||||
: ListView(
|
||||
children: [
|
||||
SizedBox(height: 24),
|
||||
for (Veggie veggie in model.favoriteVeggies)
|
||||
Padding(
|
||||
padding: EdgeInsets.fromLTRB(16, 0, 16, 24),
|
||||
child: VeggieHeadline(veggie),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
@@ -13,24 +13,16 @@ import 'package:veggieseasons/styles.dart';
|
||||
import 'package:veggieseasons/widgets/veggie_card.dart';
|
||||
|
||||
class ListScreen extends StatelessWidget {
|
||||
List<Widget> _generateVeggieRows(List<Veggie> veggies, Preferences prefs,
|
||||
{bool inSeason = true}) {
|
||||
final cards = List<Widget>();
|
||||
|
||||
for (Veggie veggie in veggies) {
|
||||
cards.add(Padding(
|
||||
padding: EdgeInsets.only(left: 16.0, right: 16.0, bottom: 24.0),
|
||||
child: FutureBuilder<Set<VeggieCategory>>(
|
||||
future: prefs.preferredCategories,
|
||||
builder: (context, snapshot) {
|
||||
final data = snapshot.data ?? Set<VeggieCategory>();
|
||||
return VeggieCard(
|
||||
veggie, inSeason, data.contains(veggie.category));
|
||||
}),
|
||||
));
|
||||
}
|
||||
|
||||
return cards;
|
||||
Widget _generateVeggieRow(veggie, Preferences prefs, {bool inSeason = true}) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(left: 16, right: 16, bottom: 24),
|
||||
child: FutureBuilder<Set<VeggieCategory>>(
|
||||
future: prefs.preferredCategories,
|
||||
builder: (context, snapshot) {
|
||||
final data = snapshot.data ?? Set<VeggieCategory>();
|
||||
return VeggieCard(veggie, inSeason, data.contains(veggie.category));
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -38,42 +30,46 @@ class ListScreen extends StatelessWidget {
|
||||
return CupertinoTabView(
|
||||
builder: (context) {
|
||||
String dateString = DateFormat("MMMM y").format(DateTime.now());
|
||||
|
||||
final appState =
|
||||
ScopedModel.of<AppState>(context, rebuildOnChange: true);
|
||||
final prefs =
|
||||
ScopedModel.of<Preferences>(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(appState.availableVeggies, prefs));
|
||||
|
||||
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(appState.unavailableVeggies, prefs,
|
||||
inSeason: false));
|
||||
|
||||
return DecoratedBox(
|
||||
decoration: BoxDecoration(color: Color(0xffffffff)),
|
||||
child: ListView(
|
||||
children: rows,
|
||||
child: ListView.builder(
|
||||
itemCount: appState.allVeggies.length + 2,
|
||||
itemBuilder: (context, index) {
|
||||
if (index == 0) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 24, 16, 16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(dateString.toUpperCase(), style: Styles.minorText),
|
||||
Text('In season today', style: Styles.headlineText),
|
||||
],
|
||||
),
|
||||
);
|
||||
} else if (index <= appState.availableVeggies.length) {
|
||||
return _generateVeggieRow(
|
||||
appState.availableVeggies[index - 1],
|
||||
prefs,
|
||||
);
|
||||
} else if (index <= appState.availableVeggies.length + 1) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 24, 16, 16),
|
||||
child: Text('Not in season', style: Styles.headlineText),
|
||||
);
|
||||
} else {
|
||||
int relativeIndex =
|
||||
index - (appState.availableVeggies.length + 2);
|
||||
return _generateVeggieRow(
|
||||
appState.unavailableVeggies[relativeIndex], prefs,
|
||||
inSeason: false);
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
@@ -39,7 +39,7 @@ class _SearchScreenState extends State<SearchScreen> {
|
||||
|
||||
Widget _createSearchBox() {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: SearchBar(
|
||||
controller: controller,
|
||||
focusNode: focusNode,
|
||||
@@ -51,7 +51,7 @@ class _SearchScreenState extends State<SearchScreen> {
|
||||
if (veggies.isEmpty) {
|
||||
return Center(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24.0),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24),
|
||||
child: Text(
|
||||
'No veggies matching your search terms were found.',
|
||||
style: Styles.headlineDescription,
|
||||
@@ -64,7 +64,7 @@ class _SearchScreenState extends State<SearchScreen> {
|
||||
itemCount: veggies.length,
|
||||
itemBuilder: (context, i) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(left: 16.0, right: 16.0, bottom: 24.0),
|
||||
padding: EdgeInsets.only(left: 16, right: 16, bottom: 24),
|
||||
child: VeggieHeadline(veggies[i]),
|
||||
);
|
||||
},
|
||||
|
||||
@@ -139,7 +139,7 @@ class SettingsScreen extends StatelessWidget {
|
||||
return Row(
|
||||
children: [
|
||||
Text(snapshot.data?.toString() ?? ''),
|
||||
SizedBox(width: 8.0),
|
||||
SizedBox(width: 8),
|
||||
SettingsNavigationIndicator(),
|
||||
],
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user