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