lazy_g_sync 2.1.0 lazy_g_sync: ^2.1.0 copied to clipboard
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;
}
}