-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 53bca18
Showing
25 changed files
with
2,009 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import 'package:flutter/material.dart'; | ||
import './screens/category_meals_screen.dart'; | ||
import './screens/meal_detail_screen.dart'; | ||
import './screens/tab_screen.dart'; | ||
import './screens/filters_screen.dart'; | ||
import './screens/categories_screen.dart'; | ||
import './dummy-data.dart'; | ||
import './models/meal.dart'; | ||
|
||
void main() => runApp(MyApp()); | ||
|
||
class MyApp extends StatefulWidget { | ||
@override | ||
_MyAppState createState() => _MyAppState(); | ||
} | ||
|
||
class _MyAppState extends State<MyApp> { | ||
Map<String, bool> _filters = { | ||
'gluten': false, | ||
'lactose': false, | ||
'vegan': false, | ||
'vegetarian': false, | ||
}; | ||
|
||
List<Meal> _availableMeals = DUMMY_MEALS; | ||
List<Meal> _favoriteMeals = []; | ||
|
||
void _setFilters(Map<String, bool> filterData) { | ||
setState(() { | ||
_filters = filterData; | ||
|
||
_availableMeals = DUMMY_MEALS.where((meal) { | ||
if (_filters['gluten'] && !meal.isGlutenFree) { | ||
return false; | ||
} | ||
if (_filters['lactose'] && !meal.isLactoseFree) { | ||
return false; | ||
} | ||
if (_filters['vegan'] && !meal.isVegan) { | ||
return false; | ||
} | ||
if (_filters['vegetarian'] && !meal.isVegetarian) { | ||
return false; | ||
} | ||
return true; | ||
}).toList(); | ||
}); | ||
} | ||
|
||
void _toggleFavorite(String mealId) { | ||
final existingIndex = _favoriteMeals.indexWhere( | ||
(meal) => meal.id == mealId, | ||
); | ||
if (existingIndex >= 0) { | ||
setState(() { | ||
_favoriteMeals.removeAt(existingIndex); | ||
}); | ||
} else { | ||
setState(() { | ||
_favoriteMeals.add( | ||
DUMMY_MEALS.firstWhere((meal) => meal.id == mealId), | ||
); | ||
}); | ||
} | ||
} | ||
|
||
bool _isMealFavorite(String id) { | ||
return _favoriteMeals.any((meal) => meal.id == id); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return MaterialApp( | ||
title: 'DeliMeals', | ||
theme: ThemeData( | ||
primarySwatch: Colors.pink, | ||
accentColor: Colors.amber, | ||
canvasColor: Color.fromRGBO(255, 254, 229, 1), | ||
fontFamily: 'Raleway', | ||
textTheme: ThemeData.light().textTheme.copyWith( | ||
bodyText1: TextStyle( | ||
color: Color.fromRGBO(20, 51, 51, 1), | ||
), | ||
bodyText2: TextStyle( | ||
color: Color.fromRGBO(20, 51, 51, 1), | ||
), | ||
headline6: TextStyle( | ||
fontSize: 20, | ||
fontFamily: 'RobotoCondensed', | ||
fontWeight: FontWeight.bold, | ||
), | ||
), | ||
), | ||
// home: CategoriesScreen(), | ||
initialRoute: '/', | ||
routes: { | ||
'/': (ctx) => TabsScreen(_favoriteMeals), | ||
CategoryMealsScreen.routeName: (ctx) => | ||
CategoryMealsScreen(_availableMeals), | ||
MealDetailScreen.routeName: (ctx) => MealDetailScreen(_toggleFavorite, _isMealFavorite), | ||
FiltersScreen.routeName: (ctx) => FiltersScreen(_filters, _setFilters), | ||
}, | ||
onGenerateRoute: (settings) { | ||
print(settings.arguments); | ||
return MaterialPageRoute( | ||
builder: (ctx) => CategoriesScreen(), | ||
); | ||
}, | ||
onUnknownRoute: (settings) { | ||
return MaterialPageRoute( | ||
builder: (ctx) => CategoriesScreen(), | ||
); | ||
}, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
class Category { | ||
final String id; | ||
final String title; | ||
final Color color; | ||
|
||
const Category({ | ||
@required this.id, | ||
@required this.title, | ||
this.color = Colors.orange, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import 'package:flutter/foundation.dart'; | ||
|
||
enum Complexity { Simple, Challenging, Hard } | ||
|
||
enum Affordability { | ||
Affordable, | ||
Pricey, | ||
Luxurious, | ||
} | ||
|
||
class Meal { | ||
final String id; | ||
final List<String> categories; | ||
final String title; | ||
final String imageUrl; | ||
final List<String> ingredients; | ||
final List<String> steps; | ||
final int duration; | ||
final Complexity complexity; | ||
final Affordability affordability; | ||
final bool isGlutenFree; | ||
final bool isLactoseFree; | ||
final bool isVegan; | ||
final bool isVegetarian; | ||
|
||
const Meal({ | ||
@required this.id, | ||
@required this.categories, | ||
@required this.title, | ||
@required this.imageUrl, | ||
@required this.ingredients, | ||
@required this.steps, | ||
@required this.duration, | ||
@required this.complexity, | ||
@required this.affordability, | ||
@required this.isGlutenFree, | ||
@required this.isLactoseFree, | ||
@required this.isVegan, | ||
@required this.isVegetarian, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import 'package:flutter/material.dart'; | ||
import '../dummy-data.dart'; | ||
import '../widgets/category_item.dart'; | ||
|
||
class CategoriesScreen extends StatelessWidget { | ||
@override | ||
Widget build(BuildContext context) { | ||
return GridView( | ||
padding: const EdgeInsets.all(25), | ||
children: DUMMY_CATEGORIES | ||
.map( | ||
(catData) => CategoryItem( | ||
catData.id, | ||
catData.title, | ||
catData.color, | ||
), | ||
) | ||
.toList(), | ||
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent( | ||
maxCrossAxisExtent: 200, | ||
childAspectRatio: 3 / 2, | ||
crossAxisSpacing: 20, | ||
mainAxisSpacing: 20, | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_complete_guide/widgets/meal_item.dart'; | ||
import '../models/meal.dart'; | ||
import '../dummy-data2.dart'; | ||
|
||
class CategoryMealsScreen extends StatefulWidget { | ||
static const routeName = '/category-meals'; | ||
|
||
final List<Meal> _availableMeals; | ||
|
||
CategoryMealsScreen(this._availableMeals); | ||
|
||
@override | ||
_CategoryMealsScreenState createState() => _CategoryMealsScreenState(); | ||
// final String categoryId; | ||
// final String categoryTitle; | ||
|
||
// CategoryMealsScreen(this.categoryId, this.categoryTitle); | ||
} | ||
|
||
class _CategoryMealsScreenState extends State<CategoryMealsScreen> { | ||
String categoryTitle; | ||
List<Meal> displayedMeals; | ||
var _loadedInitData = false; | ||
|
||
@override | ||
void initState() { | ||
// ... | ||
super.initState(); | ||
} | ||
|
||
@override | ||
void didChangeDependencies() { | ||
if (!_loadedInitData) { | ||
final routeArgs = | ||
ModalRoute.of(context).settings.arguments as Map<String, String>; | ||
categoryTitle = routeArgs['title']; | ||
final categoryId = routeArgs['id']; | ||
displayedMeals = widget._availableMeals.where((meal) { | ||
return meal.categories.contains(categoryId); | ||
}).toList(); | ||
_loadedInitData = true; | ||
} | ||
super.didChangeDependencies(); | ||
} | ||
|
||
void _removeMeal(String mealId) { | ||
setState(() { | ||
displayedMeals.removeWhere((meal) => meal.id == mealId); | ||
}); | ||
} | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: Text(categoryTitle), | ||
), | ||
body: Center( | ||
child: ListView.builder( | ||
itemBuilder: (ctx, index) { | ||
return MealItem( | ||
id: displayedMeals[index].id, | ||
title: displayedMeals[index].title, | ||
imageUrl: displayedMeals[index].imageUrl, | ||
duration: displayedMeals[index].duration, | ||
affordability: displayedMeals[index].affordability, | ||
complexity: displayedMeals[index].complexity, | ||
); | ||
}, | ||
itemCount: displayedMeals.length, | ||
), | ||
), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import 'package:flutter/material.dart'; | ||
import '../models/meal.dart'; | ||
import '../widgets/meal_item.dart'; | ||
|
||
class FavoritesScreen extends StatelessWidget { | ||
final List<Meal> favoriteMeals; | ||
|
||
FavoritesScreen(this.favoriteMeals); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
if (favoriteMeals.isEmpty) { | ||
return Center( | ||
child: Text('You have no favorites yet - start adding some!'), | ||
); | ||
} else { | ||
return ListView.builder( | ||
itemBuilder: (ctx, index) { | ||
return MealItem( | ||
id: favoriteMeals[index].id, | ||
title: favoriteMeals[index].title, | ||
imageUrl: favoriteMeals[index].imageUrl, | ||
duration: favoriteMeals[index].duration, | ||
affordability: favoriteMeals[index].affordability, | ||
complexity: favoriteMeals[index].complexity, | ||
); | ||
}, | ||
itemCount: favoriteMeals.length, | ||
); | ||
} | ||
} | ||
} |
Oops, something went wrong.