{"id":17168922,"url":"https://github.com/ciriousjoker/shared_preferences_typed","last_synced_at":"2026-05-19T10:04:16.410Z","repository":{"id":61974825,"uuid":"453928941","full_name":"ciriousjoker/shared_preferences_typed","owner":"ciriousjoker","description":"A type-safe wrapper around shared_preferences, inspired by ts-localstorage.","archived":false,"fork":false,"pushed_at":"2022-02-01T10:50:01.000Z","size":8,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-01-29T23:28:47.650Z","etag":null,"topics":["dart","flutter","sharedpreferences","sharedpreferences-wrapper","type-safety"],"latest_commit_sha":null,"homepage":"https://pub.dev/packages/shared_preferences_typed","language":"Dart","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ciriousjoker.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-01-31T08:27:46.000Z","updated_at":"2022-01-31T08:33:14.000Z","dependencies_parsed_at":"2022-10-24T13:45:33.668Z","dependency_job_id":null,"html_url":"https://github.com/ciriousjoker/shared_preferences_typed","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ciriousjoker%2Fshared_preferences_typed","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ciriousjoker%2Fshared_preferences_typed/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ciriousjoker%2Fshared_preferences_typed/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ciriousjoker%2Fshared_preferences_typed/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ciriousjoker","download_url":"https://codeload.github.com/ciriousjoker/shared_preferences_typed/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245330907,"owners_count":20597865,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dart","flutter","sharedpreferences","sharedpreferences-wrapper","type-safety"],"created_at":"2024-10-14T23:13:23.577Z","updated_at":"2026-05-19T10:04:15.548Z","avatar_url":"https://github.com/ciriousjoker.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Typed Shared Preferences\n\n[![pub package](https://img.shields.io/pub/v/shared_preferences_typed.svg)](https://pub.dartlang.org/packages/shared_preferences_typed)\n\nA type-safe wrapper around [shared_preferences](https://pub.dev/packages/shared_preferences), inspired by [ts-localstorage](https://www.npmjs.com/package/ts-localstorage).\n\n## Why?\n\n- Dart compiler now prevents you from writing a `bool` to an `int` key\n- You can organize everything related to [SharedPreferences] in one file, not just the string keys\n- You don't need to call `SharedPreferences.getInstance()` anywhere anymore\n\n## Usage\n\n- You create a `PrefKey` or a `PrefKeyNullable`, pass a string as a key and a default value that's returned when the value doesn't exist in the SharedPreferences.\n- In case of `PrefKeyNullable`, the default value is still required to guarantee type safety, but it's not actually used anywhere\n\nCheck `test/shared_preferences_typed_test.dart` for a more detailed example, here are the most common use cases:\n\n### Basic example (non-nullable)\n\n```dart\n/// Description\nconst key = PrefKey(\"some_key\", true);\n\nfinal valueBefore = await key.read(); // -\u003e true (default value)\nawait key.write(false); // -\u003e Value is now false\n```\n\n### Basic example (nullable)\n\n```dart\n/// Description\nconst key = PrefKeyNullable(\"some_key\", true);\n\nfinal valueBefore = await key.read(); // -\u003e null\nawait key.write(false); // -\u003e Value is now false\n```\n\n### Existing SharedPreferences instance (non-nullable)\n\n```dart\nfinal prefs = await SharedPreferences.instance();\n\n/// Description\nconst key = PrefKey(\"some_key\", true);\n\nfinal valueBefore = await key.readSync(prefs); // -\u003e true (default value)\nawait key.write(false); // -\u003e Value is now false\n```\n\n### Existing SharedPreferences instance (nullable)\n\n```dart\nfinal prefs = await SharedPreferences.instance();\n\n/// Description\nconst key = PrefKeyNullable(\"some_key\", true);\n\nfinal valueBefore = await key.readSync(prefs); // -\u003e null\nawait key.writeSync(false, prefs); // -\u003e Value is now false\n```\n\n## Additional information\n\n- Using an existing SharedPreferences instance has no performance gain if you don't also use it elsewhere. However, the sync methods have benefits when you really can't have `await` somewhere.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fciriousjoker%2Fshared_preferences_typed","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fciriousjoker%2Fshared_preferences_typed","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fciriousjoker%2Fshared_preferences_typed/lists"}