Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Persisting data locally in Flutter

Persisting data locally in Flutter

Danvick Miller

May 21, 2021
Tweet

More Decks by Danvick Miller

Other Decks in Programming

Transcript

  1. Why • Storing user data, preferences & tokens • Caching

    remote requests • Building offline (or offline-first) apps Example: Password Managers or apps used in remote regions with intermittent internet
  2. Key-value stores • Easily save basic data as key-value pairs

    in a private persisted dictionary. • Used for app preferences, keys and session information. • Example: Shared Preferences which uses NSUserDefaults on iOS and macOS, SharedPreferences on Android, etc.
  3. Local files • Save arbitrary files to internal or external

    device storage. • Flutter can read/write files to internal as well as external storage. • Applications have access to an application-specific directory where files can be stored. • Often used for blob data or data file caches (i.e. disk image cache)
  4. SQL Databases • Persist relational data in tables within an

    application specific database • Used for complex local data manipulation or for raw speed • SQLite is the most common SQL database. Usually used with ORMs to make data manipulation easy. • SQLite database file is stored in your application-specific directory. • Examples of ORMs: Moor
  5. NoSQL Databases • Persist data in collections and documents •

    Stores unstructured, semi-structured, or structured data • Can be developer-friendly - Enable easy updates to schemas and fields • Examples: Hive, Sembast, ObjectDB
  6. Notes: • All the persistance options may be interchangable; choose

    optimal solution • Data stored persisted can be deleted by the user; will also be deleted once the app is uninstalled • When pushing an update always handle migration of data structures (tables and collections) when there are changes