managing-shared-preferences
Skill7 starsChanged 8 months agoMITView on GitHub
SharedPreferences (v2.5.5) for Flutter providing simple persistent key-value storage for non-sensitive user settings and app preferences. Use this skill when storing user preferences (theme mode, language selection, font size), app settings and configuration, feature flags or A/B test assignments, simple cache data, onboarding completion status, last selected values (filters, sort options), user consent flags, or any non-sensitive data that survives app restarts. Supports String, int, double, bool, and StringList types. NOT suitable for storing tokens, passwords, API keys, or any sensitive/encrypted data (use flutter_secure_storage instead). Ideal for quick persistent storage without database overhead.
In this repository41 other files it gives its agents.
- .github/copilot-instructions.mdCopilot instructions
- skill-creatorSkill
- flutter-dbSkill
- flutter-routingSkill
- flutter-state-managementSkill
- configuring-codemagicSkill
- applying-effective-dartSkill
- deploying-with-fastlaneSkill
- integrating-firebaseSkill
- implementing-fl-chartSkill
- integrating-google-adsSkill
- animating-flutter-widgetsSkill
- routing-with-autorouteSkill
- implementing-flutter-blocSkill
- configuring-deep-linksSkill
- persisting-data-with-driftSkill
- building-flutter-production-appsSkill
- generating-flutter-uiSkill
- routing-with-gorouterSkill
- managing-hive-storageSkill
- using-flutter-hooksSkill
- running-flutter-isolatesSkill
- managing-flutter-provider-stateSkill
- implementing-responsive-layoutsSkill
- implementing-riverpodSkill
- managing-secure-storageSkill
- flutter-setupSkill
- implementing-flutter-social-authSkill
- flutter-testingSkill
- using-fpdartSkill
- generating-freezed-modelsSkill
- configuring-github-actionsSkill
- building-jaspr-web-appsSkill
- testing-with-marionetteSkill
- implementing-openapi-in-dartSkill
- integrating-revenuecatSkill
- integrating-sentrySkill
- developing-serverpod-backendSkill
- building-shadcn-flutter-uiSkill
- integrating-supabaseSkill
- converting-ts-to-dartSkill
The file
We split this skill into the rules it gives an agent
5 rules. About 0 are common, 5 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈5
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 24
Create a type-safe static wrapper to prevent key fragmentation:
- Distinctive: line 124
No Sensitive Data: NEVER store passwords, tokens, API keys, or PII.
- Distinctive: line 125
Type Safety: Always use static wrappers to prevent string key typos.
- Distinctive: line 126
Size Limit: Keep stored data small. Not suitable for large datasets or complex objects.
- Distinctive: line 127
Synchronous After Init: After initialization, getters are synchronous.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
SharedPreferences Simple Storage Guide
Goal
Implement lightweight key-value storage for non-sensitive app settings and user preferences using SharedPreferences. Best for simple configuration data that persists across app sessions.
Process
Phase 1: Install Dependencies
dependencies:
shared_preferences: ^2.5.5Phase 2: Create Static Wrapper (Best Practice)
Create a type-safe static wrapper to prevent key fragmentation:
import 'package:shared_preferences/shared_preferences.dart';
class Prefs {
static late SharedPreferences _instance;
static Future<void> init() async {
_instance = await SharedPreferences.getInstance();
}
// Theme preference
static bool get isDarkMode => _instance.getBool(_Keys.isDarkMode) ?? false;
static Future<void> setDarkMode(bool value) => _instance.setBool(_Keys.isDarkMode, value);
// User name
static String? get userName => _instance.getString(_Keys.userName);
static Future<void> setUserName(String value) => _instance.setString(_Keys.userName, value);
// Onboarding completed
static bool get hasCompletedOnboarding => _instance.getBool(_Keys.onboardingCompleted) ?? false;
static Future<void> setOnboardingCompleted(bool value) => _instance.setBool(_Keys.onboardingCompleted, value);
// Feature flags
static bool get isFeatureXEnabled => _instance.getBool(_Keys.featureX) ?? false;
static Future<void> setFeatureX(bool value) => _instance.setBool(_Keys.featureX, value);
// Clear all preferences
static Future<void> clear() => _instance.clear();
}
class _Keys {
static const String isDarkMode = 'is_dark_mode';
static const String userName = 'user_name';
static const String onboardingCompleted = 'onboarding_completed';
static const String featureX = 'feature_x_enabled';
}Phase 3: Initialize in main()
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Prefs.init();
runApp(MyApp());
}Phase 4: Usage in App
// Read
final isDark = Prefs.isDarkMode;
final name = Prefs.userName ?? 'Guest';
// Write
await Prefs.setDarkMode(true);
await Prefs.setUserName('John Doe');
// Clear all
await Prefs.clear();Phase 5: Integration with State Management
With Riverpod:
final darkModeProvider = StateNotifierProvider<DarkModeNotifier, bool>((ref) {
return DarkModeNotifier();
});
class DarkModeNotifier extends StateNotifier<bool> {
DarkModeNotifier() : super(Prefs.isDarkMode);
Future<void> toggle() async {
state = !state;
await Prefs.setDarkMode(state);
}
}With BLoC:
class ThemeCubit extends Cubit<ThemeState> {
ThemeCubit() : super(ThemeState(isDark: Prefs.isDarkMode));
Future<void> toggleTheme() async {
final newValue = !state.isDark;
await Prefs.setDarkMode(newValue);
emit(state.copyWith(isDark: newValue));
}
}Constraints
- No Sensitive Data: NEVER store passwords, tokens, API keys, or PII. Use SecureStorage instead.
- Type Safety: Always use static wrappers to prevent string key typos.
- Size Limit: Keep stored data small. Not suitable for large datasets or complex objects.
- Synchronous After Init: After initialization, getters are synchronous. Only setters are async.
- Platform Limits: iOS has NSUserDefaults limits (~1MB recommended).
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

