lazy_g_sync 1.1.1 copy "lazy_g_sync: ^1.1.1" to clipboard
lazy_g_sync: ^1.1.1 copied to clipboard

outdated

Single file sync using Google Drive `appData` space. A bridge between [lazy.GDrive], [lazy.GSignIn] and local data/content.

example/lazy_g_sync_example.dart

import 'package:flutter/material.dart';
import 'package:lazy_g_sync/lazy_g_sync.dart' as lazy;
import 'package:lazy_sign_in_google/lazy_sign_in_google.dart' as lazy;

// THIS IS ***NOT A COMPLETE APP***, BUT SAMPLE STARTING POINT

// Your google sign in should have scope 'https://www.googleapis.com/auth/drive.appdata'
final globalLazySignIn = lazy.SignInGoogle(
  clientId: 'Google OAuth Client ID',
  scopes: [
    'email',
    'https://www.googleapis.com/auth/drive.appdata',
  ],
);
final lazyGSync = lazy.GSync(lazyGSignIn: globalLazySignIn);
final someLocalContent = SomeLocalContent();

void main() {
  // -- Register [SomeLocalContent] with [lazyGSync]

  // Tell GSync how to get content
  lazyGSync.getLocalContent = () => someLocalContent.toString();
  // Tell GSync how to get filename
  lazyGSync.getFilename = () => 'localContent.txt';
  // Tell GSync how to get local last save time
  lazyGSync.getLocalSaveTime = () => someLocalContent.lastSave;
  // Tell GSync who will send a save/sync trigger
  lazyGSync.localSaveNotifier = someLocalContent.saveNotifier;
  // Tell GSync how to set local content
  lazyGSync.setContent =
      (content, dateTime) => someLocalContent.content = content;
  runApp(const MyApp());
}

/// This can be local settings/preferences/content
class SomeLocalContent {
  String content = '';
  DateTime lastSave = DateTime(0);

  @override
  String toString() {
    return content;
  }

  ValueNotifier<bool> saveNotifier = ValueNotifier(true);

  /// [save] will also trigger the notifier
  save(String v) {
    content = v;
    saveNotifier.value = !saveNotifier.value;
  }
}
3
likes
0
pub points
0%
popularity

Publisher

verified publisherjsiu.dev

Single file sync using Google Drive `appData` space. A bridge between [lazy.GDrive], [lazy.GSignIn] and local data/content.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, googleapis, lazy_extensions, lazy_g_drive, lazy_log, lazy_sign_in

More

Packages that depend on lazy_g_sync