Commit 7f21347d authored by m-spi's avatar m-spi

Remove fav + Capital letter categories

parent caea29bb
......@@ -2,13 +2,20 @@ import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'app_state.dart';
extension StringExtensions on String {
String capitalize() {
return "${this[0].toUpperCase()}${this.substring(1)}";
}
}
class FavoritePage extends StatefulWidget {
@override
_FavoritePageState createState() => _FavoritePageState();
}
class _FavoritePageState extends State<FavoritePage> {
String? selectedCategory;
String selectedCategory = 'All';
@override
Widget build(BuildContext context) {
......@@ -16,19 +23,19 @@ class _FavoritePageState extends State<FavoritePage> {
return Scaffold(
appBar: AppBar(
title: Text('Favorite Books'),
title: Text('Favorites'),
actions: [
DropdownButton<String>(
value: selectedCategory,
onChanged: (String? newValue) {
setState(() {
selectedCategory = newValue;
selectedCategory = newValue ?? 'All';
});
},
items: state.uniqueCategories.map((String category) {
items: (['All'] + state.uniqueCategories.toList()).map((String category) {
return DropdownMenuItem<String>(
value: category,
child: Text(category),
child: Text(category.capitalize()),
);
}).toList(),
),
......@@ -42,7 +49,7 @@ class _FavoritePageState extends State<FavoritePage> {
itemCount: state.favorites.length,
itemBuilder: (context, index) {
Map<String, dynamic> book = state.getFav(index);
if (selectedCategory != null && book['category'] != selectedCategory) {
if (selectedCategory != 'All' && book['category'] != selectedCategory) {
return Container(); // Return an empty container if the book doesn't belong to the selected category
}
return GestureDetector(
......@@ -79,6 +86,8 @@ class ImageScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
TindCodeState state = Provider.of<TindCodeState>(context);
return Scaffold(
appBar: AppBar(
title: Text(book['title']),
......@@ -133,7 +142,8 @@ class ImageScreen extends StatelessWidget {
SizedBox(height: 16.0),
ElevatedButton(
onPressed: () {
//TODO: LOGIC HERE
state.removeDataFromFav(book);
Navigator.of(context).pop();
},
child: Text('Remove from favorites', style: TextStyle(fontSize: 16)),
),
......
......@@ -24,12 +24,27 @@ class _TindCodeContentState extends State<TindCodeContent> {
super.didChangeDependencies();
state = Provider.of<TindCodeState>(context);
if (remainingI.contains(-1)){
remainingI = List<int>.generate(state.data.length, (i) => i);
remainingI.shuffle();
getList();
currentImageIndex = remainingI.removeAt(0);
}
}
void getList() {
remainingI = List<int>.
generate(state.data.length, (i) => i).
where((i) => ! state.favorites.contains(i)).
toList();
if (remainingI.length==0) {
remainingI = List<int>.
generate(state.data.length, (i) => i);
}
remainingI.shuffle();
}
@override
Widget build(BuildContext context) {
......@@ -39,6 +54,14 @@ class _TindCodeContentState extends State<TindCodeContent> {
double containerHeight = constraints.maxHeight;
void handleSwipe(int direction) {
if (remainingI.length == 0){
showDialog(
context: context,
builder: (_) => NoMoreBooksWidget(),
);
getList();
}
if (direction == 1) {
// Swipe right
state.addIndexToFav(currentImageIndex);
......@@ -49,24 +72,6 @@ class _TindCodeContentState extends State<TindCodeContent> {
currentImageIndex = remainingI.removeAt(0);
}
if (remainingI.length == 0){
showDialog(
context: context,
builder: (_) => NoMoreBooksWidget(),
);
remainingI = List<int>.
generate(state.data.length, (i) => i).
where((i) => ! state.favorites.contains(i)).
toList();
if (remainingI.length==0) {
remainingI = List<int>.
generate(state.data.length, (i) => i);
};
remainingI.shuffle();
}
}
return GestureDetector(
......
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