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
e90e42b3
Commit
e90e42b3
authored
Feb 12, 2024
by
m-spi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
correct var init
parent
1393677b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
11 deletions
+27
-11
data.json
tp1/assets/data.json
+1
-1
app_state.dart
tp1/lib/app_state.dart
+26
-10
No files found.
tp1/assets/data.json
View file @
e90e42b3
...
...
@@ -110,7 +110,7 @@
"category"
:
"course"
,
"title"
:
"Learn Programming With JavaScript"
,
"author"
:
"Olga Volkova, Will Alexander"
,
"publisher"
:
"OpenCla
t
ssrooms"
,
"publisher"
:
"OpenClassrooms"
,
"completion_time"
:
"15 hours"
,
"description"
:
"This course is designed to teach you the fundamentals of the JavaScript programming language and to give you lots of practice along the way!"
,
"image"
:
"assets/images/LearnProgrammingWithJS.jpg"
,
...
...
tp1/lib/app_state.dart
View file @
e90e42b3
...
...
@@ -7,32 +7,48 @@ const String filePath = '../assets/data.json';
class
TindBookState
extends
ChangeNotifier
{
String
input
=
""
;
late
var
data
;
List
<
dynamic
>
data
=
<
dynamic
>[]
;
List
<
int
>
favorites
=
<
int
>[];
void
loadData
()
async
{
this
.
input
=
await
rootBundle
.
loadString
(
filePath
);
this
.
data
=
jsonDecode
(
input
)[
'data'
];
input
=
await
rootBundle
.
loadString
(
filePath
);
data
=
jsonDecode
(
input
)[
'data'
];
notifyListeners
();
}
Map
<
String
,
dynamic
>
getFav
(
int
index
)
{
return
this
.
data
[
this
.
favorites
[
index
]];
return
data
[
favorites
[
index
]];
}
void
addIndexToFav
(
int
index
)
{
if
(!
favorites
.
contains
(
index
)){
favorites
.
add
(
index
);
notifyListeners
();
}
}
void
addDataToFav
(
Map
<
String
,
dynamic
>
obj
){
favorites
.
add
(
this
.
data
.
indexOf
(
obj
));
if
(!
favorites
.
contains
(
data
.
indexOf
(
obj
))){
favorites
.
add
(
data
.
indexOf
(
obj
));
notifyListeners
();
}
}
void
addIndexToFav
(
int
index
)
{
if
(!
favorites
.
contains
(
index
)){
favorites
.
add
(
index
);
void
removeIndexFromFav
(
int
index
)
{
if
(
favorites
.
contains
(
index
)){
favorites
.
remove
(
index
);
notifyListeners
();
}
}
void
removeDataFromFav
(
Map
<
String
,
dynamic
>
obj
){
if
(
favorites
.
contains
(
data
.
indexOf
(
obj
))){
favorites
.
remove
(
data
.
indexOf
(
obj
));
notifyListeners
();
}
}
List
<
String
>
get
categories
=>
[
for
(
Map
<
String
,
dynamic
>
entry
in
data
)
entry
[
'category'
]];
Set
<
String
>
get
uniqueCategories
=>
this
.
categories
.
toSet
();
Set
<
String
>
get
uniqueCategories
=>
categories
.
toSet
();
}
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