mirror of
https://github.com/flutter/samples.git
synced 2026-06-25 15:49:43 +00:00
Migrate compass_app to SharedPreferencesAsync (#2841)
## Description Migrated `SharedPreferences` usage in `compass_app` to `SharedPreferencesAsync` to align with the latest `shared_preferences` recommendations. ### Changes made * Replaced `SharedPreferences.getInstance()` usages * Updated async preference reads with awaited getters * Migrated token persistence logic * Updated test setup preference clearing logic Fixes #2720 ## Pre-launch Checklist * [x] I read the [[Flutter Style Guide](https://github.com/flutter/flutter/blob/master/docs/contributing/Style-guide-for-Flutter-repo.md)] *recently*, and have followed its advice. * [x] I signed the [[CLA](https://cla.developers.google.com/)]. * [x] I read the [[Contributors Guide](https://github.com/flutter/samples/blob/main/CONTRIBUTING.md)]. * [ ] I have added sample code updates to the [[changelog](https://chatgpt.com/CHANGELOG.md)]. * [ ] I updated/added relevant documentation (doc comments with `///`). <!-- Links --> [Flutter Style Guide]: https://github.com/flutter/flutter/blob/master/docs/contributing/Style-guide-for-Flutter-repo.md [CLA]: https://cla.developers.google.com/ [Discord]: https://github.com/flutter/flutter/blob/master/docs/contributing/Chat.md [Contributors Guide]: https://github.com/flutter/samples/blob/main/CONTRIBUTING.md [changelog]: ../CHANGELOG.md Co-authored-by: Eric Windmill <eric@ericwindmill.com>
This commit is contained in:
@@ -65,10 +65,12 @@ class _MyHomePageState extends State<MyHomePage> {
|
||||
// Write the value to [SharedPreferences] which will get read on the
|
||||
// [SimpleDatabase]'s isolate. For this example the value is always true
|
||||
// just for demonstration purposes.
|
||||
final Future<void> sharedPreferencesSet = SharedPreferences.getInstance()
|
||||
.then(
|
||||
(sharedPreferences) => sharedPreferences.setBool('isDebug', true),
|
||||
);
|
||||
final SharedPreferencesAsync sharedPreferences = SharedPreferencesAsync();
|
||||
|
||||
final Future<void> sharedPreferencesSet = sharedPreferences.setBool(
|
||||
'isDebug',
|
||||
true,
|
||||
);
|
||||
final Future<Directory> tempDirFuture = path_provider
|
||||
.getTemporaryDirectory();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user