Skip to content

feat(storage-kit): implement SharedPreferencesStore for persistent key-value storage #117

Description

@husamettinarabaci

Is your feature request related to a problem?

The SharedPreferencesStore skeleton class exists in packages/storage_kit/lib/key_value/shared_preferences_store.dart but needs full implementation to provide a concrete KeyValueStore implementation using SharedPreferences for persistent, simple data storage.

Describe the solution you'd like

Implement a fully functional SharedPreferencesStore class that implements the KeyValueStore interface using Flutter's shared_preferences package, providing persistent storage for simple key-value data across app sessions.

What is SharedPreferencesStore and why do we need it?

SharedPreferencesStore is a concrete implementation of KeyValueStore using SharedPreferences, providing simple persistent storage for app preferences and settings.

Why it's important:

  • Persistence: Data survives app restarts
  • Performance: Fast synchronous access after initialization
  • Platform Support: Works on iOS, Android, web, desktop
  • Simple Data: Perfect for preferences and settings
  • Standard Solution: Industry-standard for simple storage

Common use cases:

  • User app preferences
  • Theme selection (dark/light mode)
  • Language preference
  • Onboarding completion flag
  • Feature flags
  • Simple caching

Required Deliverables

  1. SharedPreferencesStore implementation with:

    • Initialize SharedPreferences
    • Implement all KeyValueStore methods
    • Type-safe getters/setters
    • Error handling
    • Null safety
    • Integration with shared_preferences package
    • Singleton pattern
    • Clear documentation
  2. Widgetbook stories (6-8 use cases):

    • Store string data
    • Store int data
    • Store bool data
    • Store list data
    • Retrieve stored data
    • Remove key demo
    • Clear all demo
    • Storage inspector UI
  3. SPDX headers in all source files

Key Implementation Specs

  • Implements KeyValueStore interface
  • Use shared_preferences package
  • Singleton instance: SharedPreferencesStore._()
  • Factory constructor: SharedPreferencesStore.instance
  • initialize() returns Future
  • All methods delegate to SharedPreferences
  • Error handling for storage failures
  • Null safety with nullable returns
  • Type conversions handled internally

Acceptance Criteria

  • SharedPreferencesStore implements KeyValueStore
  • initialize() loads SharedPreferences
  • getString() retrieves string values
  • setString() stores string values
  • getInt() retrieves int values
  • setInt() stores int values
  • getBool() retrieves bool values
  • setBool() stores bool values
  • getDouble() retrieves double values
  • setDouble() stores double values
  • getStringList() retrieves lists
  • setStringList() stores lists
  • remove() deletes keys
  • clear() removes all data
  • containsKey() checks existence
  • Singleton pattern implemented
  • Error handling works
  • All 6-8 Widgetbook stories created and functional
  • SPDX headers present in all files
  • Code follows STYLE_GUIDE.md standards
  • Unit tests cover storage operations

Related Files

  • packages/storage_kit/lib/key_value/shared_preferences_store.dart (skeleton)
  • packages/storage_kit/lib/key_value/key_value_store.dart (interface)
  • widgetbook_kit/lib/stories/storage_kit/shared_preferences_store_story.dart (Widgetbook)

Impact: Primary simple storage solution; used throughout the app

Priority: High

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kanban:mobileMobile application development and mobile UI taskstype:featureNew feature or capability

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions