Menu

1 / 2

Flutter Local Storage Guide — SharedPreferences vs Hive vs SQLite

DEV Community·kanta13jp1·6 months ago
#XNJAondd
#flutter#dart#webdev#indiedev#await
Reading 0:00
15s threshold

Flutter Local Storage Guide — SharedPreferences vs Hive vs SQLite

Choosing the right local storage solution in Flutter directly impacts performance and code simplicity. Here's a practical breakdown of the three main options.

SharedPreferences — Key-Value Settings

Best for small primitives: user settings, theme, login state.

dependencies : shared_preferences : ^2.3.0

Enter fullscreen mode

Exit fullscreen mode

class SettingsService { static const _themeKey = 'theme_mode' ;

Future < void > saveTheme ( String theme ) async { final prefs = await SharedPreferences . getInstance (); await prefs . setString ( _themeKey , theme ); }

Future < String > getTheme () async { final prefs = await SharedPreferences . getInstance (); return prefs . getString ( _themeKey ) ?? 'system' ; } }

Enter fullscreen mode

Exit fullscreen mode

Hive — Fast NoSQL Storage

Perfect for structured data, offline caching, and large datasets.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.