Commit 1393677b authored by Timothé KOBAK's avatar Timothé KOBAK

categories but ?

parent 0fd135d0
...@@ -2,7 +2,14 @@ import 'package:flutter/material.dart'; ...@@ -2,7 +2,14 @@ import 'package:flutter/material.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'app_state.dart'; import 'app_state.dart';
class FavoritePage extends StatelessWidget { class FavoritePage extends StatefulWidget {
@override
_FavoritePageState createState() => _FavoritePageState();
}
class _FavoritePageState extends State<FavoritePage> {
String? selectedCategory;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
TindBookState state = Provider.of<TindBookState>(context); TindBookState state = Provider.of<TindBookState>(context);
...@@ -10,6 +17,22 @@ class FavoritePage extends StatelessWidget { ...@@ -10,6 +17,22 @@ class FavoritePage extends StatelessWidget {
return Scaffold( return Scaffold(
appBar: AppBar( appBar: AppBar(
title: Text('Favorite Books'), title: Text('Favorite Books'),
actions: [
DropdownButton<String>(
value: selectedCategory,
onChanged: (String? newValue) {
setState(() {
selectedCategory = newValue;
});
},
items: state.uniqueCategories.map((String category) {
return DropdownMenuItem<String>(
value: category,
child: Text(category),
);
}).toList(),
),
],
), ),
body: GridView.builder( body: GridView.builder(
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount( gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
...@@ -18,19 +41,23 @@ class FavoritePage extends StatelessWidget { ...@@ -18,19 +41,23 @@ class FavoritePage extends StatelessWidget {
), ),
itemCount: state.favorites.length, itemCount: state.favorites.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
Map<String, dynamic> book = state.getFav(index);
if (selectedCategory != null && book['category'] != selectedCategory) {
return Container(); // Return an empty container if the book doesn't belong to the selected category
}
return GestureDetector( return GestureDetector(
onTap: () { onTap: () {
Navigator.push( Navigator.push(
context, context,
MaterialPageRoute( MaterialPageRoute(
builder: (context) => ImageScreen(book: state.getFav(index)), builder: (context) => ImageScreen(book: book),
), ),
); );
}, },
child: Padding( child: Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
child: Image.asset( child: Image.asset(
state.getFav(index)['image'], book['image'],
fit: BoxFit.cover, fit: BoxFit.cover,
), ),
), ),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment