Skip to content

Instantly share code, notes, and snippets.

@fabiancrx
Last active December 6, 2022 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabiancrx/dfc3dd6d4dd939e8559f15647e2b5253 to your computer and use it in GitHub Desktop.
Save fabiancrx/dfc3dd6d4dd939e8559f15647e2b5253 to your computer and use it in GitHub Desktop.
import 'package:shared_preferences/shared_preferences.dart';
/// A service that stores and retrieves user settings.
///
/// This class persists its data via SharedPreferences plugin
class SettingsService {
final SharedPreferences _sharedPreferences;
SettingsService(this._sharedPreferences);
/// Loads the User's last saved counter value
int counter() => int.parse(_sharedPreferences.getString('counter')??'0');
/// Updates the counter value
Future<bool> updateCounter(int newValue) => _sharedPreferences.setString('counter', '$newValue');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment