Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
amse
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Matis SPINELLI
amse
Commits
7f21347d
Commit
7f21347d
authored
Feb 12, 2024
by
m-spi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove fav + Capital letter categories
parent
caea29bb
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
27 deletions
+42
-27
favorite_page.dart
tp1/lib/favorite_page.dart
+17
-7
swipe_page.dart
tp1/lib/swipe_page.dart
+25
-20
No files found.
tp1/lib/favorite_page.dart
View file @
7f21347d
...
...
@@ -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
Book
s'
),
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
)),
),
...
...
tp1/lib/swipe_page.dart
View file @
7f21347d
...
...
@@ -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
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment