class PhotosLibraryApiModel extends Model { PhotosLibraryApiModel() { _googleSignIn.onCurrentUserChanged.listen((GoogleSignInAccount account) { _currentUser = account; if (_currentUser != null) { // Initialize the client with the new user credentials client = PhotosLibraryApiClient(_currentUser.authHeaders); } else { // Reset the client client = null; } // Reinitialize the albums updateAlbums(); notifyListeners(); }); } final LinkedHashSet _albums = LinkedHashSet(); bool hasAlbums = false; PhotosLibraryApiClient client; GoogleSignInAccount _currentUser; final GoogleSignIn _googleSignIn = GoogleSignIn(scopes: [ 'profile', 'https://www.googleapis.com/auth/photoslibrary', 'https://www.googleapis.com/auth/photoslibrary.sharing' ]); GoogleSignInAccount get user => _currentUser; bool isLoggedIn() { return _currentUser != null; } Future signIn() async { final GoogleSignInAccount user = await _googleSignIn.signIn(); if (user == null) { // User could not be signed in print('User could not be signed in.'); return false; } print('User signed in.'); return true; }