> ## Documentation Index
> Fetch the complete documentation index at: https://docs.pocketsync.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart

> Get started with PocketSync in your Flutter application

## Installation

### Requirements

* A PocketSync account (sign up at [pocketsync.dev](https://pocketsync.dev))

#### Our SDKs

<CardGroup cols={2}>
  <Card title="Flutter SDK" icon="flutter" href="https://pub.dev/packages/pocketsync_flutter" />

  <Card title="Typescript SDK (planned)" icon="globe" href="https://pocketsync.dev" />
</CardGroup>

### Add dependency

<Tabs>
  <Tab title="pubspec.yaml">
    ```yaml theme={null}
    dependencies:
      pocketsync_flutter: ^0.3.0
    ```
  </Tab>

  <Tab title="Command line">
    ```bash theme={null}
    flutter pub add pocketsync_flutter
    ```
  </Tab>
</Tabs>

### Basic setup

1. Create a project in the [PocketSync console](https://pocketsync.dev)
2. Initialize PocketSync in your app:

```dart theme={null}
import 'package:pocketsync_flutter/pocketsync_flutter.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  
  final dbPath = join(await getDatabasesPath(), 'my_app.db');
  
  try {
    await PocketSync.initialize(
      dbPath: dbPath,
      options: PocketSyncOptions(
        projectId: 'your-project-id',
        authToken: 'your-auth-token',
        serverUrl: 'https://api.pocketsync.dev',
      ),
      databaseOptions: databaseOptions,
    );

    PocketSync.instance.setUserId(userId: 'user-123');
    await PocketSync.instance.start();
  } catch (e) {
    print('Failed to initialize PocketSync: $e');
  }
}
```

## Configuration

PocketSync can be configured with various options to customize its behavior. The `PocketSyncOptions` class accepts the following parameters:

| Parameter                    | Description                                        | Default                      |
| ---------------------------- | -------------------------------------------------- | ---------------------------- |
| `projectId`                  | Your project ID from the PocketSync dashboard      | Required                     |
| `authToken`                  | Authentication token from the PocketSync dashboard | Required                     |
| `serverUrl`                  | PocketSync server URL                              | `https://api.pocketsync.dev` |
| `changeLogRetentionDays`     | Number of days to retain change logs               | 30                           |
| `syncExistingData`           | Whether to sync existing data                      | `true`                       |
| `conflictResolutionStrategy` | Strategy for resolving conflicts                   | `lastWriteWins`              |
| `customResolver`             | Custom conflict resolver function                  | `null`                       |
| `verbose`                    | Enable detailed logging                            | `false`                      |

Example configuration with custom options:

```dart theme={null}
final options = PocketSyncOptions(
  projectId: 'your-project-id',
  authToken: 'your-auth-token',
  serverUrl: 'https://api.pocketsync.dev',
  changeLogRetentionDays: 60,
  syncExistingData: true,
  conflictResolutionStrategy: ConflictResolutionStrategy.custom,
  customResolver: (localChange, remoteChange) {
    // Your custom conflict resolution logic
    return localChange;
  },
  verbose: true,
);
```

## Sync management

* Call `PocketSync.instance.start()` to start the sync process.
* Call `PocketSync.instance.stop()` to stop the sync process.
* Make sure to call `PocketSync.instance.setUserId(userId: 'user-123')` before starting the sync process. This is required to identify the user and track their changes.

## Device id generation

PocketSync will automatically generate a unique device identifier for your app. This identifier is used to track changes made by the user on this device. There are some known limitations with device id generation on iOS:

* If the app is uninstalled and reinstalled, the device id will change.
* If the app is deleted and reinstalled, the device id will change.
* If the app is deleted and reinstalled, the device id will change.

## Next Steps

* Learn about [Core concepts](/core-concepts/offline-first)
* Understand [Conflict resolution](/core-concepts/conflict-resolution)
