Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display user score on profile page #170

Merged
merged 1 commit into from
Feb 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/src/models/user_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class User {
List<int>? following;
List<int>? upvotedIssueId;
List<int>? savedIssueId;
int? totalScore;

User({
this.id,
Expand All @@ -24,6 +25,7 @@ class User {
this.following,
this.upvotedIssueId,
this.savedIssueId,
this.totalScore,
});

factory User.fromJson(Map<String, dynamic> responseData, String accessToken) {
Expand All @@ -38,6 +40,7 @@ class User {
following: responseData["follows"],
upvotedIssueId: responseData["issue_upvoted"],
savedIssueId: responseData["issue_saved"],
totalScore: responseData["total_score"] ?? 0,
);
}
}
Expand Down
23 changes: 22 additions & 1 deletion lib/src/pages/home/profile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class _UserProfileState extends ConsumerState<UserProfile> {
}
} catch (e) {}
return issueList;
}
}

Future<void> logout() async {
await ref.read(authStateNotifier.notifier).logout();
Expand Down Expand Up @@ -334,6 +334,27 @@ class _UserProfileState extends ConsumerState<UserProfile> {
Divider(
thickness: 2,
),
SizedBox(
child: (currentUser!.following != null)
? TextButton(
onPressed: () {},
child: Text(
(currentUser!.totalScore != null) ?
"Score : ${currentUser!.totalScore!} " :
"Score : 0 " ,
style: GoogleFonts.aBeeZee(
textStyle: TextStyle(
color: Color(0xFFDC4654),
fontSize: 15,
),
),
),
)
: null,
),
Divider(
thickness: 2,
),
],
),
),
Expand Down
1 change: 1 addition & 0 deletions lib/src/util/api/user_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class UserApiClient {
user.following = decodedResponse["follows"].cast<int>();
user.upvotedIssueId = decodedResponse["issue_upvoted"].cast<int>();
user.savedIssueId = decodedResponse["issue_saved"].cast<int>();
user.totalScore = int.parse(decodedResponse["total_score"]);
} catch (e) {
print(e);
}
Expand Down