Skip to content

Commit

Permalink
animations & readme
Browse files Browse the repository at this point in the history
  • Loading branch information
lukovskiy541 committed Oct 14, 2024
1 parent a02244e commit 782ce4a
Show file tree
Hide file tree
Showing 11 changed files with 87 additions and 49 deletions.
17 changes: 1 addition & 16 deletions meals_app/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1 @@
# meals_app

A new Flutter project.

## Getting Started

This project is a starting point for a Flutter application.

A few resources to get you started if this is your first Flutter project:

- [Lab: Write your first Flutter app](https://docs.flutter.dev/get-started/codelab)
- [Cookbook: Useful Flutter samples](https://docs.flutter.dev/cookbook)

For help getting started with Flutter development, view the
[online documentation](https://docs.flutter.dev/), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
![alt text](Screenshot_1728941484.png) ![alt text](Screenshot_1728941494.png) ![alt text](Screenshot_1728941499.png) ![alt text](Screenshot_1728941503.png) ![alt text](Screenshot_1728941505.png) ![alt text](Screenshot_1728941518.png) ![alt text](Screenshot_1728941524.png)
Binary file added meals_app/Screenshot_1728941484.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added meals_app/Screenshot_1728941494.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added meals_app/Screenshot_1728941499.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added meals_app/Screenshot_1728941503.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added meals_app/Screenshot_1728941505.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added meals_app/Screenshot_1728941518.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added meals_app/Screenshot_1728941524.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
79 changes: 58 additions & 21 deletions meals_app/lib/screens/categories.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,40 @@ import 'package:meals_app/models/meal.dart';
import 'package:meals_app/screens/meals.dart';
import 'package:meals_app/widgets/category_grid_item.dart';

class CategoriesScreen extends StatelessWidget {
const CategoriesScreen({super.key, required this.avaliableMeals });
class CategoriesScreen extends StatefulWidget {
const CategoriesScreen({super.key, required this.avaliableMeals});

final List<Meal> avaliableMeals;


@override
State<CategoriesScreen> createState() => _CategoriesScreenState();
}

class _CategoriesScreenState extends State<CategoriesScreen>
with SingleTickerProviderStateMixin {
late AnimationController _animationController;

@override
void initState() {
super.initState();
_animationController = AnimationController(
vsync: this,
duration: Duration(milliseconds: 300),
lowerBound: 0,
upperBound: 1,
);

_animationController.forward();
}

@override
void dispose() {
_animationController.dispose();
super.dispose();
}

void _selectCategory(BuildContext context, Category category) {
final filteredMeals = avaliableMeals
final filteredMeals = widget.avaliableMeals
.where((meal) => meal.categories.contains(category.id))
.toList();
Navigator.push(
Expand All @@ -22,31 +47,43 @@ class CategoriesScreen extends StatelessWidget {
builder: (ctx) => MealsScreen(
title: category.title,
meals: filteredMeals,

),
),
);
}

@override
Widget build(BuildContext context) {
return GridView(
padding: const EdgeInsets.all(24),
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: 3 / 2,
crossAxisSpacing: 20,
mainAxisSpacing: 20,
return AnimatedBuilder(
animation: _animationController,
child: GridView(
padding: const EdgeInsets.all(24),
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
childAspectRatio: 3 / 2,
crossAxisSpacing: 20,
mainAxisSpacing: 20,
),
children: [
for (final category in availableCategories)
CategoryGridItem(
category: category,
onSelectCategory: () {
_selectCategory(context, category);
},
),
],
),
builder: (context, child) => SlideTransition(
position: Tween(
begin: const Offset(0, 0.3),
end: const Offset(0, 0),
).animate(
CurvedAnimation(
parent: _animationController, curve: Curves.easeInOut),
),
child: child,
),
children: [
for (final category in availableCategories)
CategoryGridItem(
category: category,
onSelectCategory: () {
_selectCategory(context, category);
},
),
],
);
}
}
25 changes: 19 additions & 6 deletions meals_app/lib/screens/meal_details_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,31 @@ class MealDetailsScreen extends ConsumerWidget {
wasAdded ? 'Meal added as favorite.' : 'Meal removed.'),
));
},
icon: Icon(isFavorite ? Icons.star : Icons.star_border),
icon: AnimatedSwitcher(
transitionBuilder: (child, animation) {
return RotationTransition(
turns: Tween(begin: 0.5, end: 1.0).animate(animation),
child: child,

);
},
duration: const Duration(milliseconds: 300),
child: Icon(isFavorite ? Icons.star : Icons.star_border, key: ValueKey(isFavorite),),
),
),
],
),
body: SingleChildScrollView(
child: Column(
children: [
Image.network(
meal.imageUrl,
height: 300,
width: double.infinity,
fit: BoxFit.cover,
Hero(
tag: meal.id,
child: Image.network(
meal.imageUrl,
height: 300,
width: double.infinity,
fit: BoxFit.cover,
),
),
const SizedBox(
height: 14,
Expand Down
15 changes: 9 additions & 6 deletions meals_app/lib/widgets/meal_item.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,15 @@ class MealItem extends StatelessWidget {
},
child: Stack(
children: [
FadeInImage(
placeholder: MemoryImage(kTransparentImage),
image: NetworkImage(meal.imageUrl),
fit: BoxFit.cover,
height: 200,
width: double.infinity,
Hero(
tag: meal.id,
child: FadeInImage(
placeholder: MemoryImage(kTransparentImage),
image: NetworkImage(meal.imageUrl),
fit: BoxFit.cover,
height: 200,
width: double.infinity,
),
),
Positioned(
bottom: 0,
Expand Down

0 comments on commit 782ce4a

Please sign in to comment.