flutter-databases
MVVM-compliant data layer for Flutter with Repository pattern, stateless Services, and intelligent local caching strategies.
- Guides selection of persistence technology (shared_preferences, sqflite, drift, hive_ce, isar_community, or file I/O) based on data type, size, and relational complexity
- Implements Repository as single source of truth, isolating DatabaseService and ApiClient as private stateless dependencies
- Provides complete code examples for domain models, SQLite operations, and offline-first sync patterns with parameterized queries to prevent SQL injection
- Enforces architectural constraints: UI layer accesses only Repository, services remain stateless, database connection verified before operations
flutter-data-layer-persistence
Goal
Architects and implements a robust, MVVM-compliant data layer in Flutter applications. Establishes a single source of truth using the Repository pattern, isolates external API and local database interactions into stateless Services, and implements optimal local caching strategies (e.g., SQLite via sqflite) based on data requirements. Assumes a pre-configured Flutter environment.
Decision Logic
Evaluate the user's data persistence requirements using the following decision tree to select the appropriate caching strategy:
- Is the data small, simple key-value pairs (e.g., user preferences, theme settings)?
- Yes: Use
shared_preferences.
- Yes: Use
- Is the data a large, structured, relational dataset requiring fast inserts/queries?
- Yes: Use On-device relational databases (
sqfliteordrift).
- Yes: Use On-device relational databases (
- Is the data a large, unstructured/non-relational dataset?
- Yes: Use On-device non-relational databases (
hive_ceorisar_community).
- Yes: Use On-device non-relational databases (
- Is the data primarily API response caching?
- Yes: Use a lightweight remote caching system or interceptors.
- Is the data primarily images?
- Yes: Use
cached_network_imageto store images on the file system.
- Yes: Use
- Is the data too large for
shared_preferencesbut doesn't require querying?- Yes: Use direct File System I/O.
More from flutter/skills
flutter-building-layouts
Builds Flutter layouts using the constraint system and layout widgets. Use when creating or refining the UI structure of a Flutter application.
10.6Kflutter-architecting-apps
Architects a Flutter application using the recommended layered approach (UI, Logic, Data). Use when structuring a new project or refactoring for scalability.
10.4Kflutter-animating-apps
Implements animated effects, transitions, and motion in a Flutter app. Use when adding visual feedback, shared element transitions, or physics-based animations.
9.6Kflutter-managing-state
Manages application and ephemeral state in a Flutter app. Use when sharing data between widgets or handling complex UI state transitions.
9.6Kflutter-theming-apps
Customizes the visual appearance of a Flutter app using the theming system. Use when defining global styles, colors, or typography for an application.
9.5Kflutter-implementing-navigation-and-routing
Handles routing, navigation, and deep linking in a Flutter application. Use when moving between screens or setting up URL-based navigation.
9.3K