Easy way to access Shared Preference, or we can call like session. For more customization, you can use shared_preferences package.

Features

  1. User
  2. Token
  3. Custom

1. User

final user = {
'id': 'aha276avsUHUa',
'email': '[email protected]',
'username': 'indre',
};
DSession.setUser(user);

DSession.getUser().then((value) {
    debugPrint(value.toString());
    if (value != null) {
        debugPrint(value['email']);
    }
});

DSession.removeUser();

2. Token

final data = {
    'token': 'askuaysuabs',
    'expire': '2023-10-10 01:01:01',
};
DSession.setToken(data);

DSession.getToken().then((value) {
    debugPrint(value.toString());
});

DSession.removeToken();

3. Custom

For custom, you must set the key. The keyword must be other than:

  • d_session_user
  • d_session_token
DSession.setCustom('isDark', true);

final data = await DSession.getCustom('isDark');
debugPrint(data.toString());
bool isDark = data ?? false;
if(isDark){
    debugPrint('Dark theme activated');
}

DSession.removeCustom('isDark');

Additional information

...

Libraries

d_session