Explicit Animations end
This commit is contained in:
+62
-19
@@ -6,7 +6,7 @@ import 'package:flutter_meals/widgets/category_grid_item.dart';
|
||||
import 'package:flutter_meals/screens/meals.dart';
|
||||
import 'package:flutter_meals/models/category.dart';
|
||||
|
||||
class CategoriesScreen extends StatelessWidget {
|
||||
class CategoriesScreen extends StatefulWidget {
|
||||
const CategoriesScreen({
|
||||
super.key,
|
||||
required this.availableMeals,
|
||||
@@ -14,8 +14,36 @@ class CategoriesScreen extends StatelessWidget {
|
||||
|
||||
final List<Meal> availableMeals;
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() => _CategoriesScreenState();
|
||||
}
|
||||
|
||||
class _CategoriesScreenState extends State<CategoriesScreen>
|
||||
with SingleTickerProviderStateMixin {
|
||||
late AnimationController _animationController;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
_animationController = AnimationController(
|
||||
vsync: this,
|
||||
duration: const Duration(milliseconds: 300),
|
||||
lowerBound: 0,
|
||||
upperBound: 1,
|
||||
);
|
||||
|
||||
_animationController.forward();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_animationController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _selectCategory(BuildContext context, Category category) {
|
||||
final filteredMeals = availableMeals
|
||||
final filteredMeals = widget.availableMeals
|
||||
.where((meal) => meal.categories.contains(category.id))
|
||||
.toList();
|
||||
|
||||
@@ -31,24 +59,39 @@ class CategoriesScreen extends StatelessWidget {
|
||||
|
||||
@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: [
|
||||
// availableCategories.map((category) => CategoryGridItem(category: category)).toList()
|
||||
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: [
|
||||
// availableCategories.map((category) => CategoryGridItem(category: category)).toList()
|
||||
for (final category in availableCategories)
|
||||
CategoryGridItem(
|
||||
category: category,
|
||||
onSelectCategory: () {
|
||||
_selectCategory(context, category);
|
||||
},
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user