managing-shared-preferences — independently scanned and version-tracked by SaferSkills.
SaferSkills independently audited managing-shared-preferences (Agent Skill) and scored it 100/100 (green). The audit ran 55 deterministic rules across Security, Supply Chain, Maintenance, Transparency, and Community; it found 0 high-severity and 0 lower-severity findings. The full rule-by-rule trace and per-finding evidence are below. Free, methodology-open.
Findings & checks · 0 flagged
Every scanned point with the score it earned and what moved between them.
First recorded scan — no prior version to compare against.
The primary manifest — the file an agent reads to learn what this artifact does.
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.
dependencies:
shared_preferences: ^2.5.5Create 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';
}void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Prefs.init();
runApp(MyApp());
}// 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();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));
}
}~30 seconds. Free. No account. Every finding cites a rule and a line of evidence.