Skip to content

Instantly share code, notes, and snippets.

@huxaiphaer
Created May 13, 2020 22:02
Show Gist options
  • Save huxaiphaer/bffc746f77ffa7a7e1392b2ff1534b3d to your computer and use it in GitHub Desktop.
Save huxaiphaer/bffc746f77ffa7a7e1392b2ff1534b3d to your computer and use it in GitHub Desktop.
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