Created
May 13, 2020 22:02
-
-
Save huxaiphaer/bffc746f77ffa7a7e1392b2ff1534b3d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProfilePreferencesBloc { | |
final _user = BehaviorSubject<AuthResponse>(); | |
static const String USER = "USER"; | |
//Getters | |
Stream<AuthResponse> get user => _user.stream; | |
//Setters | |
Function(AuthResponse) get changeUserProfileDetails => _user.sink.add; | |
editProfileDetails(user) async { | |
SharedPreferences prefs = await SharedPreferences.getInstance(); | |
prefs.remove(USER); | |
prefs.setString(USER, json.encode(user).toString()); | |
} | |
getProfileDetails() async { | |
SharedPreferences prefs = await SharedPreferences.getInstance(); | |
String user = prefs.get(USER); | |
AuthResponse authResponse = json.decode(user); | |
if (authResponse != null) { | |
changeUserProfileDetails(authResponse); | |
} | |
changeUserProfileDetails(authResponse); | |
} | |
dispose() { | |
_user.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment