potatoes_secured_preferences 1.0.2 copy "potatoes_secured_preferences: ^1.0.2" to clipboard
potatoes_secured_preferences: ^1.0.2 copied to clipboard

A Preferences service with secure storage capabilities

Potatoes Secured Preferences #

A Preferences service with secure storage capabilities. Built for Potatoes.

Getting Started #

This package provides an extension of Potatoes' PreferencesService using flutter_secure_storage to provide encryption capabilities.

Usage #

You simply need to extend SecuredPreferencesService to define you persistence logic.

class AppSecuredPreferences extends SecuredPreferencesService {
  static const String _authTokenKey = 'auth_token';
  static const String _userIdKey = 'user_id';

  AppSecuredPreferences(super.preferences, super.secureStorage);

  // no need to encrypt, we use regular SharedPreferences
  Future<void> setUserId(String value) {
    return preferences.setString(_userIdKey, value);
  }
  
  String? get userId => preferences.getString(_userIdKey);
  
  // encrypt sensitive value
  Future<void> setAuthToken(String value) {
    return secureStorage.write(key: _authTokenKey, value: value);
  }
  
  @override
  FutureOr<Map<String, String>> getAuthHeaders() async {
    // get the authentication token from Secure Storage
    final token = await secureStorage.read(key: _authTokenKey);

    // return the auth map to inject into API queries
    return {
      'Authorization': 'Bearer $token'
    };
  }
}
copied to clipboard

And enjoy using it!

// new instance
securedPreferencesService = AppSecuredPreferences(
  sharedPreferences,
  flutterSecureStorage
);

securedPreferencesService.setUserId("user id here");
securedPreferencesService.userId; // retrieve user id value
securedPreferencesService.setAuthToken("token value here");

// clean both SharedPreferences and Secure Storage
securedPreferencesService.clear();
copied to clipboard
1
likes
140
points
129
downloads

Publisher

verified publishercaelis-tech.studio

Weekly Downloads

2024.08.27 - 2025.03.11

A Preferences service with secure storage capabilities

Homepage
Repository (GitHub)
View/report issues

Topics

#potatoes #shared-preferences #storage #secure

Documentation

API reference

License

MIT (license)

Dependencies

flutter, flutter_secure_storage, potatoes

More

Packages that depend on potatoes_secured_preferences