From fdeb576ffa0b56ad27a0597d88d60e3eedfc3b82 Mon Sep 17 00:00:00 2001 From: ezyyeah Date: Fri, 30 Dec 2022 15:10:23 +0100 Subject: [PATCH] profile picture in db --- filcnaplo/lib/api/providers/user_provider.dart | 5 +++++ filcnaplo/lib/database/init.dart | 4 ++-- filcnaplo/lib/models/user.dart | 4 ++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/filcnaplo/lib/api/providers/user_provider.dart b/filcnaplo/lib/api/providers/user_provider.dart index ae09d41..ccbbe19 100644 --- a/filcnaplo/lib/api/providers/user_provider.dart +++ b/filcnaplo/lib/api/providers/user_provider.dart @@ -21,6 +21,7 @@ class UserProvider with ChangeNotifier { Role? get role => user?.role; Student? get student => user?.student; String? get nickname => user?.nickname; + String get picture => user?.picture ?? ""; String? get displayName => user?.displayName; final SettingsProvider _settings; @@ -70,4 +71,8 @@ class UserProvider with ChangeNotifier { List getUsers() { return _users.values.toList(); } + + void refresh() { + notifyListeners(); + } } diff --git a/filcnaplo/lib/database/init.dart b/filcnaplo/lib/database/init.dart index 7ea23bc..958c3c8 100644 --- a/filcnaplo/lib/database/init.dart +++ b/filcnaplo/lib/database/init.dart @@ -22,7 +22,7 @@ const settingsDB = DatabaseStruct("settings", { // YOU'VE BEEN WARNED!!! const usersDB = DatabaseStruct("users", { "id": String, "name": String, "username": String, "password": String, "institute_code": String, "student": String, "role": int, - "nickname": String // premium only + "nickname": String, "picture": String // premium only }); const userDataDB = DatabaseStruct("user_data", { "id": String, "grades": String, "timetable": String, "exams": String, "homework": String, "messages": String, "notes": String, @@ -62,7 +62,7 @@ Future initDB(DatabaseProvider database) async { await migrateDB( db, struct: usersDB, - defaultValues: {"role": 0, "nickname": ""}, + defaultValues: {"role": 0, "nickname": "", "picture": ""}, ); await migrateDB(db, struct: userDataDB, defaultValues: { "grades": "[]", "timetable": "[]", "exams": "[]", "homework": "[]", "messages": "[]", "notes": "[]", "events": "[]", "absences": "[]", diff --git a/filcnaplo/lib/models/user.dart b/filcnaplo/lib/models/user.dart index 44714a6..dcffd09 100644 --- a/filcnaplo/lib/models/user.dart +++ b/filcnaplo/lib/models/user.dart @@ -14,6 +14,7 @@ class User { Student student; Role role; String nickname; + String picture; String get displayName => nickname != '' ? nickname : name; @@ -26,6 +27,7 @@ class User { required this.student, required this.role, this.nickname = "", + this.picture = "", }) { if (id != null) { this.id = id; @@ -44,6 +46,7 @@ class User { student: Student.fromJson(jsonDecode(map["student"])), role: Role.values[map["role"] ?? 0], nickname: map["nickname"] ?? "", + picture: map["picture"] ?? "", ); } @@ -57,6 +60,7 @@ class User { "student": jsonEncode(student.json), "role": role.index, "nickname": nickname, + "picture": picture, }; }