Last active
December 6, 2022 18:20
-
-
Save fabiancrx/dfc3dd6d4dd939e8559f15647e2b5253 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
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