Skip to content

Instantly share code, notes, and snippets.

@huseyinyildirim
Last active June 26, 2020 08:06
Show Gist options
  • Save huseyinyildirim/92f28f03d9bac0ec7876329639c3abe6 to your computer and use it in GitHub Desktop.
Save huseyinyildirim/92f28f03d9bac0ec7876329639c3abe6 to your computer and use it in GitHub Desktop.
shared_preferences_example.dart
import 'package:shared_preferences/shared_preferences.dart'
class SharedPreferencesTest {
///
/// SharedPreferences Kütüphanesi Örneği
///
final String _notifications = "notifications";
final String _sortingOrder = "sortOrder";
/// ------------------------------------------------------------
/// Kullanıcının bildirim ayarlarını alır
/// ------------------------------------------------------------
Future<bool> getNotifications() async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
return prefs.getBool(_notifications) ?? false;
}
/// ----------------------------------------------------------
/// Kullanıcının bildirimlere izin verme kararını kaydeden yöntem
/// ----------------------------------------------------------
Future<bool> setNotifications(bool value) async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
return prefs.setBool(_notifications, value);
}
/// ------------------------------------------------------------
/// Sıralama düzeninde kullanıcının kararını döndüren yöntem
/// ------------------------------------------------------------
Future<String> getSortingOrder() async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
return prefs.getString(_sortingOrder) ?? 'name';
}
/// ----------------------------------------------------------
/// Sıralama düzeninde kullanıcının kararını kaydeden yöntem
/// ----------------------------------------------------------
Future<bool> setSortingOrder(String value) async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
return prefs.setString(_sortingOrder, value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment