user abstract method
Returns the authenticated user information from userId
.
A call to this method will always cause a communication process with the Duolingo API. If you want to reuse the cached response object, use cachedUser.
Example:
void main() async {
final duolingo = Duolingo.instance;
final authResponse = await duolingo.authenticate(
username: 'test_username',
password: 'test_password',
);
final userResponse = await duolingo.user(userId: authResponse.userId);
print(userResponse.name);
print(userResponse.lingots);
for (final course in userResponse.courses) {
print(course.title);
print(course.xp);
}
// Skill information is stored in a hierarchical structure.
final skillBook = userResponse.currentCourse.skillBook;
for (final chapter in skillBook.chapters) {
for (final content in chapter.contents) {
if (content.isAccessible) {
print(content.name);
print(content.proficiency);
print(content.tipsAndNotes);
}
}
}
// If you don't like the nested structure,
// you can use the toFlat method to make the structure flat.
//
// If you use the toFlat method, all the skill information that
// exists in SkillBook will be returned as a new list.
for (final skill in skillBook.toFlat()) {
if (skill.isAccessible) {
print(skill.name);
print(skill.proficiency);
print(skill.tipsAndNotes);
}
}
}
Implementation
Future<UserResponse> user({
String userId,
});