cloud_sync_shared_preferences_adapter 0.0.1-rc.2
cloud_sync_shared_preferences_adapter: ^0.0.1-rc.2 copied to clipboard
A Flutter plugin for integrating Shared Preferences sync functionality.
CloudSyncSharedPreferencesAdapter #
A local implementation of the SyncAdapter
interface from the cloud_sync
package, using SharedPreferences
for simple key-value storage.
This adapter allows apps to persist note metadata and content directly on the device β perfect for quick sync flows, offline caching, or prototyping.
β¨ Features #
- π Stores note metadata (
SyncMetadata
) and content (String
) inSharedPreferences
. - β‘ Quick and lightweight β no setup or database needed.
- π§ͺ Great for prototyping, fallback storage, or minimal local sync solutions.
π¦ Installation #
Add the required dependencies to your pubspec.yaml
:
dependencies:
shared_preferences: ^latest
cloud_sync: ^latest
cloud_sync_shared_preferences_adapter: ^latest
π Usage #
import 'package:shared_preferences/shared_preferences.dart';
import 'package:cloud_sync_shared_preferences_adapter/cloud_sync_shared_preferences_adapter.dart';
import 'your_models/sync_metadata.dart'; // Your custom SyncMetadata
void main() async {
final prefs = await SharedPreferences.getInstance();
final adapter = CloudSyncSharedPreferencesAdapter<MyMetadata>(
preferences: prefs,
metadataToJson: (meta) => jsonEncode(meta.toJson()),
metadataFromJson: (json) => MyMetadata.fromJson(jsonDecode(json)),
);
// Use the adapter with your CloudSync logic
}
π Class Overview #
class CloudSyncSharedPreferencesAdapter<M extends SyncMetadata>
extends SerializableSyncAdapter<M, String>
Constructor parameters #
preferences
: An instance ofSharedPreferences
.metadataToJson
: Function to serialize metadata toString
.metadataFromJson
: Function to deserialize metadata fromString
.prefix
: Optional key prefix for namespacing (default:"$CloudSyncSharedPreferencesAdapter"
).
β When to Use #
- π§ͺ Prototype sync flows or quick demos.
- π Store small amounts of structured content locally.
- π΄ Enable basic offline persistence.
- π Fallback adapter alongside a cloud-based adapter (e.g., Google Drive).
β οΈ Limitations #
- Not suitable for large or binary data β use
Hive
orFile
-based adapters instead. - SharedPreferences may have storage limits depending on platform.
π License #
MIT (or your projectβs license).
π Related #
cloud_sync
β The base sync framework.shared_preferences
β Simple local key-value storage.