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
Hide 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';
...
@@ -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
Book
s'
),
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
)),
),
),
...
...
tp1/lib/swipe_page.dart
View file @
7f21347d
...
@@ -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
(
...
...
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