cloud_sync_google_drive_adapter 0.0.1
cloud_sync_google_drive_adapter: ^0.0.1 copied to clipboard
A Flutter plugin for integrating Google Drive cloud sync functionality.
CloudSyncGoogleDriveAdapter #
A Google Drive-based implementation of the SyncAdapter
interface from the cloud_sync
package.
This adapter enables two-way synchronization of metadata and string-based detail content using Google Drive, storing metadata in the file's description and detailed content as file content.
β¨ Features #
- π Syncs metadata (
SyncMetadata
) and detail (String
) via Google Drive files. - π Fetches all metadata entries with a matching file name.
- πΎ Reads and writes file contents using Google Drive's API.
- π€ Automatically creates or updates files based on metadata ID.
- π Uses
appDataFolder
by default for secure, app-specific storage. - β
Supports both
DriveApi
injection and creation via an HTTP client.
π¦ Installation #
Add this to your pubspec.yaml
:
dependencies:
cloud_sync: ^latest
cloud_sync_google_drive_adapter: ^latest
googleapis: ^latest
google_sign_in: ^latest
http: ^latest
π Usage #
With Authenticated HTTP Client #
import 'package:cloud_sync_google_drive_adapter/cloud_sync_google_drive_adapter.dart';
import 'package:http/http.dart' as http;
import 'your_models/sync_metadata.dart'; // Your custom metadata model
final adapter = CloudSyncGoogleDriveAdapter<MyMetadata>.fromClient(
client: authClient,
metadataToJson: (meta) => jsonEncode(meta.toJson()),
metadataFromJson: (json) => MyMetadata.fromJson(jsonDecode(json)),
getMetadataId: (meta) => meta.id,
isCurrentMetadataBeforeOther: (a, b) => a.updatedAt.isBefore(b.updatedAt),
);
With an Existing Drive API Instance #
final adapter = CloudSyncGoogleDriveAdapter<MyMetadata>(
driveApi: driveApiInstance,
metadataToJson: ...,
metadataFromJson: ...,
getMetadataId: ...,
isCurrentMetadataBeforeOther: ...,
);
π Class Overview #
class CloudSyncGoogleDriveAdapter<M extends SyncMetadata>
extends SerializableSyncAdapter<M, String>
Constructors #
CloudSyncGoogleDriveAdapter
β for using an existingDriveApi
instance.CloudSyncGoogleDriveAdapter.fromClient
β for creatingDriveApi
from an authenticatedhttp.Client
.
Key Parameters #
Parameter | Description | Default |
---|---|---|
driveApi / client |
Authenticated API or client | (required) |
metadataToJson / FromJson |
Serialization logic for metadata | (required) |
getMetadataId |
Extracts unique ID from metadata | (required) |
isCurrentMetadataBeforeOther |
Comparison function for metadata versioning | (required) |
spaces |
Google Drive space (appDataFolder , etc.) |
'appDataFolder' |
fileName |
Name of file used for storing data | '$CloudSyncGoogleDriveAdapter' |
β When to Use #
- βοΈ You want cloud-based synchronization for structured content.
- π± Ideal for syncing notes, tasks, logs, or encrypted app data.
- π Supports multi-device sync, offline cache + recovery, etc.
π Methods #
Method | Description |
---|---|
fetchMetadataList() |
Lists all files matching the given file name. |
fetchDetail() |
Downloads and decodes file content from Drive. |
save() |
Creates or updates a file based on metadata ID. |
π§ Notes #
- Metadata is stored in the file's
description
field. - File content (detail) is stored as binary
application/octet-stream
. - Only files matching the
fileName
are read or written.
π License #
MIT (or your projectβs license)
π Related #
cloud_sync
β Core sync abstractiongoogleapis
β Google Drive API wrappergoogle_sign_in
β For authentication