Skip to content

Instantly share code, notes, and snippets.

@iapicca
Created July 31, 2024 09:43
Show Gist options
  • Save iapicca/bf57078f045882a6c8088f3ae4f50b4c to your computer and use it in GitHub Desktop.
Save iapicca/bf57078f045882a6c8088f3ae4f50b4c to your computer and use it in GitHub Desktop.
issue_152607
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
final class SharedPreferencesKeys {
static const action = 'action';
}
void main() async {
final prefsWithCache = await SharedPreferencesWithCache.create(
cacheOptions: const SharedPreferencesWithCacheOptions(
allowList: {SharedPreferencesKeys.action},
),
);
await prefsWithCache.setStringList(
SharedPreferencesKeys.action,
const ['Earth', 'Moon', 'Sun'],
);
final actions =
prefsWithCache.getStringList(SharedPreferencesKeys.action) ?? [];
runApp(
MaterialApp(
home: Material(
child: Column(
children: [
for (final action in actions) Text(action),
],
),
),
),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment