cloud_sync_shared_preferences_adapter 0.0.1 copy "cloud_sync_shared_preferences_adapter: ^0.0.1" to clipboard
cloud_sync_shared_preferences_adapter: ^0.0.1 copied to clipboard

A Flutter plugin for integrating Shared Preferences sync functionality.

CloudSyncSharedPreferencesAdapter #

A lightweight local implementation of the SyncAdapter from the cloud_sync package, powered by SharedPreferences.

Perfect for simple sync needs, offline caching, prototypes, or fallback storage β€” no database required.


✨ Features #

  • πŸ“ Persists metadata (SyncMetadata) and detail content (String) in SharedPreferences.
  • ⚑ Lightweight and fast β€” ideal for prototyping or minimal sync flows.
  • πŸ“΄ Supports offline storage with zero setup.
  • πŸ”„ Fully compatible with the cloud_sync framework.

πŸ“¦ Installation #

Add to your pubspec.yaml:

dependencies:
  cloud_sync: ^latest
  shared_preferences: ^latest
  cloud_sync_shared_preferences_adapter: ^latest

πŸš€ Usage #

import 'dart:convert';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:cloud_sync_shared_preferences_adapter/cloud_sync_shared_preferences_adapter.dart';
import 'your_models/my_metadata.dart';

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)),
    getMetadataId: (meta) => meta.id,
    isCurrentMetadataBeforeOther: (a, b) => a.updatedAt.isBefore(b.updatedAt),
  );

  // Use this adapter with CloudSync to persist your data locally.
}

🧠 Class Overview #

class CloudSyncSharedPreferencesAdapter<M extends SyncMetadata>
  extends SerializableSyncAdapter<M, String>

πŸ› οΈ Constructor Parameters #

Parameter Description Required Default
preferences Instance of SharedPreferences. βœ… –
metadataToJson Serializes metadata to a String. βœ… –
metadataFromJson Deserializes a String into metadata. βœ… –
getMetadataId Extracts the unique ID from a metadata object. βœ… –
isCurrentMetadataBeforeOther Compares two metadata objects for version ordering. βœ… –
prefix Optional prefix for namespacing stored keys. ❌ "$CloudSyncSharedPreferencesAdapter"

βœ… When to Use #

  • ⚑ Quick local sync for small apps or offline features.
  • πŸ§ͺ Ideal for demos, prototypes, or testing sync logic.
  • πŸ”™ Acts as a fallback when a cloud adapter is unavailable.

⚠️ Limitations #

  • Not suitable for large or binary data β€” use file or database-based adapters instead.
  • SharedPreferences has platform-specific size limits (~1–2MB).


πŸ“„ License #

MIT (or match your project’s license).

0
likes
160
points
90
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin for integrating Shared Preferences sync functionality.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

cloud_sync, flutter, shared_preferences

More

Packages that depend on cloud_sync_shared_preferences_adapter