pocketsync_flutter 0.4.0 copy "pocketsync_flutter: ^0.4.0" to clipboard
pocketsync_flutter: ^0.4.0 copied to clipboard

Pocketsync is a Flutter plugin that provides a simple way to sync your data between devices.

example/lib/main.dart

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:pocketsync_flutter/pocketsync_flutter.dart';
import 'package:path/path.dart';
import 'views/todo_list_view.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  String path = join(await getDatabasesPath(), 'todo_database.db');

  await PocketSync.initialize(
    options: PocketSyncOptions(
      projectId: '1d0c9a33-e5bd-4149-9971-8b2568f22469',
      authToken: 'ds_NzhkNzk3ZWE1NGE1NDA1NDk0ZGU5ODAxZDBkZjQ4MmY=',
      serverUrl: defaultTargetPlatform == TargetPlatform.android
          ? 'http://10.0.2.2:3000'
          : 'http://127.0.0.1:3000',
    ),
    databaseOptions: DatabaseOptions(
      dbPath: path,
      onCreate: (db, version) async {
        await db.execute(
          'CREATE TABLE todos(id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT, isCompleted INTEGER)',
        );
      },
    ),
  );

  // Set user ID - In a real app, this would come from your auth system
  PocketSync.instance.setUserId('test-user');

  // Start syncing
  await PocketSync.instance.start();

  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Todo App',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.blue),
        useMaterial3: true,
      ),
      home: const TodoListView(),
    );
  }
}
8
likes
0
points
65
downloads

Publisher

verified publisherpocketsync.dev

Weekly Downloads

Pocketsync is a Flutter plugin that provides a simple way to sync your data between devices.

Homepage
Repository (GitHub)
View/report issues

Topics

#local-first #offline-first #sync

License

unknown (license)

Dependencies

crypto, device_info_plus, dio, flutter, meta, socket_io_client, sqflite, sqflite_common_ffi, sqlite3_flutter_libs, uuid

More

Packages that depend on pocketsync_flutter