cloud_sync_google_drive_adapter 0.0.1

SDKdartflutter
Platformandroidioswindowslinuxmacosweb

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 existing DriveApi instance.
  • CloudSyncGoogleDriveAdapter.fromClient – for creating DriveApi from an authenticated http.Client.

Key Parameters

ParameterDescriptionDefault
driveApi / clientAuthenticated API or client(required)
metadataToJson / FromJsonSerialization logic for metadata(required)
getMetadataIdExtracts unique ID from metadata(required)
isCurrentMetadataBeforeOtherComparison function for metadata versioning(required)
spacesGoogle Drive space (appDataFolder, etc.)'appDataFolder'
fileNameName 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

MethodDescription
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)