Skip to content

Commit

Permalink
My first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
SumitPareek2401 committed Jun 1, 2023
0 parents commit 53bca18
Show file tree
Hide file tree
Showing 25 changed files with 2,009 additions and 0 deletions.
Binary file added Raleway-Black.ttf
Binary file not shown.
Binary file added Raleway-Bold.ttf
Binary file not shown.
Binary file added Raleway-Regular.ttf
Binary file not shown.
Binary file added RobotoCondensed-Bold.ttf
Binary file not shown.
Binary file added RobotoCondensed-Italic.ttf
Binary file not shown.
Binary file added RobotoCondensed-Light.ttf
Binary file not shown.
Binary file added RobotoCondensed-Regular.ttf
Binary file not shown.
408 changes: 408 additions & 0 deletions dummy-data.dart

Large diffs are not rendered by default.

408 changes: 408 additions & 0 deletions dummy-data2.dart

Large diffs are not rendered by default.

116 changes: 116 additions & 0 deletions main.dart
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(),
);
},
);
}
}
13 changes: 13 additions & 0 deletions models/category.dart
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,
});
}
41 changes: 41 additions & 0 deletions models/meal.dart
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,
});
}
27 changes: 27 additions & 0 deletions screens/categories_screen.dart
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,
),
);
}
}
76 changes: 76 additions & 0 deletions screens/category_meals_screen.dart
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,
),
),
);
}
}
32 changes: 32 additions & 0 deletions screens/favorites_screen.dart
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,
);
}
}
}
Loading

0 comments on commit 53bca18

Please sign in to comment.