Commit e90e42b3 authored by m-spi's avatar m-spi

correct var init

parent 1393677b
......@@ -110,7 +110,7 @@
"category": "course",
"title": "Learn Programming With JavaScript",
"author": "Olga Volkova, Will Alexander",
"publisher": "OpenClatssrooms",
"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",
......
......@@ -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();
}
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