cachedUser abstract method

Future<UserResponse> cachedUser({
  1. String userId,
})

Returns cached the authenticated user information from userId.

The first call to this cachedUser method will always result in a communication with the Duolingo API because there is no cached UserResponse. In the second and subsequent method calls, the cached UserResponse from the first method call will be returned.

The type and data structure of the response is consistent with the user method. However, please note that the cached data is returned from this method, so unless you explicitly delete this cached object data, the cached response object will always be returned.

To delete the explicitly cached UserResponse, call the cleanCachedUser method.

Example:

void main() async {
 final duolingo = Duolingo.instance;

 final authResponse = await duolingo.authenticate(
   username: 'test_username',
   password: 'test_password',
 );

 final userResponse = await duolingo.cachedUser(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);
   }
 }

 // Delete cache.
 duolingo.cleanCachedUser();
}

Implementation

Future<UserResponse> cachedUser({
  String userId,
});