From 5f040e65453105ad66e4759c43c882be8e6aba2a Mon Sep 17 00:00:00 2001 From: Andrew Brogdon Date: Fri, 7 Sep 2018 09:34:32 -0700 Subject: [PATCH] Adding favorites screen to veggieseasons. (#16) --- veggieseasons/lib/screens/favorites.dart | 41 ++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/veggieseasons/lib/screens/favorites.dart b/veggieseasons/lib/screens/favorites.dart index 774109691..a1a99c78a 100644 --- a/veggieseasons/lib/screens/favorites.dart +++ b/veggieseasons/lib/screens/favorites.dart @@ -4,18 +4,55 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/widgets.dart'; +import 'package:scoped_model/scoped_model.dart'; +import 'package:veggieseasons/data/model.dart'; +import 'package:veggieseasons/data/veggie.dart'; 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 _buildScaffoldBody(BuildContext context) { + final model = ScopedModel.of(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 = [ + 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 CupertinoPageScaffold( navigationBar: CupertinoNavigationBar( - middle: Text('My Garden'), + middle: Text('Your Garden'), ), backgroundColor: Styles.scaffoldBackground, child: Center( - child: Text('Not yet implemented.'), + child: _buildScaffoldBody(context), ), ); }