pocketbase_drift library

A powerful, offline-first Flutter client for PocketBase, backed by the reactive persistence of Drift (the Flutter & Dart flavor of moor).

This library extends the official PocketBase Dart SDK to provide a seamless offline-first experience. It automatically caches data from your PocketBase instance into a local SQLite database, allowing your app to remain fully functional even without a network connection. Changes made while offline are queued and automatically retried when connectivity is restored.

Key features include:

  • Offline CRUD operations.
  • Automatic data synchronization.
  • Reactive data streams for UI updates.
  • Local caching of collections and records using Drift.
  • Powerful local querying capabilities (filtering, sorting, pagination).
  • Relation expansion from the local cache.
  • Full-text search on cached data.
  • Authentication persistence.
  • File and image caching with PocketBaseImageProvider.

To get started, replace your standard PocketBase client with $PocketBase.database() from this package.

Classes

$$BlobFilesTableAnnotationComposer
$$BlobFilesTableFilterComposer
$$BlobFilesTableOrderingComposer
$$BlobFilesTableReferences
$$BlobFilesTableTableManager
$$CachedResponsesTableAnnotationComposer
$$CachedResponsesTableFilterComposer
$$CachedResponsesTableOrderingComposer
$$CachedResponsesTableTableManager
$$ServicesTableAnnotationComposer
$$ServicesTableFilterComposer
$$ServicesTableOrderingComposer
$$ServicesTableReferences
$$ServicesTableTableManager
$AuthStore
$BackupService
$BatchRequest
A request queued in a batch operation.
$BatchResult
Result of a single batch operation.
$BatchService
A service for executing batch/transactional operations with offline support.
$BlobFilesTable
$CachedResponsesTable
$CollectionService
$DataBaseManager
$FileService
$HealthService
$LogService
$PocketBase
$RealtimeService
$RecordService
$ServicesTable
$SettingsService
$SubBatchService
A sub-service for queuing batch operations on a specific collection.
$TextEntriesAnnotationComposer
$TextEntriesFilterComposer
$TextEntriesOrderingComposer
$TextEntriesTableManager
AppleClientSecret
Response DTO of the Apple OAuth2 Client Secret response.
AsyncAuthStore
AsyncAuthStore is a pluggable AuthStore implementation that could be used with any external async persistent layer (shared_preferences, hive, local file, etc.).
AuthAlertConfig
Response DTO of a single collection auth alert config.
AuthMethodMFA
Response DTO of mfa auth method option.
AuthMethodOAuth2
Response DTO of oauth2 auth method option.
AuthMethodOTP
Response DTO of otp auth method option.
AuthMethodPassword
Response DTO of password/identity auth method option.
AuthMethodProvider
Response DTO of a single OAuth2 provider.
AuthMethodsList
Response DTO of the allowed authentication methods.
AuthStore
Base authentication store management service that keep tracks of the authenticated User/Admin model and its token.
AuthStoreEvent
Event object that holds an AuthStore state.
BackupFileInfo
Response DTO of a backup file info entry.
BackupService
The service that handles the Backup and restore APIs.
BaseCrudService<M extends Jsonable>
Base generic crud service that is intented to be used by all other crud services.
BatchResult
Response DTO of a single batch request result.
BatchService
The service that handles the Batch/transactional APIs.
BlobFile
BlobFilesCompanion
CachedResponse
CachedResponsesCompanion
CollectionField
Response DTO of a single collection schema field.
CollectionModel
Response DTO of a single collection model.
CollectionService
The service that handles the Collection APIs.
ConnectivityService
A service that monitors the device's network connectivity status.
CronJob
Response DTO of a cron job item.
CronService
The service that handles the Cron APIs.
DataBase
EmailTemplateConfig
Response DTO of a single collection email template config.
FileService
The service that handles the File APIs.
FilterParser
A class responsible for parsing a PocketBase filter string into a valid SQL WHERE clause for Drift.
FilterTerm
Represents a single term in a filter expression, like name = "value".
HealthCheck
Response DTO of a health check.
HealthService
The service that handles the Health APIs.
Jsonable
Interface for JSON serializable classes.
LogModel
Response DTO of a single log model.
LogService
The service that handles the Log APIs.
LogStat
Response DTO of a single log statistic summary item.
MaintenanceResult
Result of running runMaintenance on the PocketBase client.
MFAConfig
Response DTO of a single collection mfa auth config.
OAuth2Config
Response DTO of a single collection oauth2 auth config.
OTPConfig
Response DTO of a single collection otp auth config.
OTPResponse
Response DTO of a otp request response.
PasswordAuthConfig
Response DTO of a single collection password auth config.
PocketBase
The main PocketBase API client.
PocketBaseImageProvider
An ImageProvider that fetches and caches images from a PocketBase instance.
RealtimeService
The service that handles the Realtime APIs.
RecordAuth
Response DTO of the record authentication data.
RecordModel
Response DTO of a single record model.
RecordService
The service that handles the Record APIs.
RecordSubscriptionEvent
Response DTO of a single realtime subscription event.
ResultList<M extends Jsonable>
Response DTO of a generic paginated list.
RetryProgressEvent
SearchResult
SearchServiceResult
Service
ServicesCompanion
SettingsService
The service that handles the Settings APIs.
SubBatchService
TextEntries
TextEntriesCompanion
TextEntry
TokenConfig
Response DTO of a single collection token config.

Enums

LogicalOperator
Represents a logical operator in a filter expression.
RequestPolicy
Defines how data should be fetched and synchronized between local cache and remote server.
ValueType
Represents the type of a value literal

Mixins

ServiceMixin<M extends Jsonable>

Constants

isWeb → const bool

Functions

connect(String dbName, {bool logStatements = false, bool inMemory = false}) → DatabaseConnection
newId() String
Generates a random 15-character alphanumeric string compatible with PocketBase.

Typedefs

$$BlobFilesTableCreateCompanionBuilder = BlobFilesCompanion Function({Value<String?> created, required Uint8List data, Value<DateTime?> expiration, required String filename, Value<int> id, required String recordId, Value<String?> updated})
$$BlobFilesTableProcessedTableManager = ProcessedTableManager<_$DataBase, $BlobFilesTable, BlobFile, $$BlobFilesTableFilterComposer, $$BlobFilesTableOrderingComposer, $$BlobFilesTableAnnotationComposer, $$BlobFilesTableCreateCompanionBuilder, $$BlobFilesTableUpdateCompanionBuilder, (BlobFile, $$BlobFilesTableReferences), BlobFile, PrefetchHooks Function({bool recordId})>
$$BlobFilesTableUpdateCompanionBuilder = BlobFilesCompanion Function({Value<String?> created, Value<Uint8List> data, Value<DateTime?> expiration, Value<String> filename, Value<int> id, Value<String> recordId, Value<String?> updated})
$$CachedResponsesTableCreateCompanionBuilder = CachedResponsesCompanion Function({Value<DateTime> cachedAt, required String requestKey, required String responseData, Value<int> rowid})
$$CachedResponsesTableProcessedTableManager = ProcessedTableManager<_$DataBase, $CachedResponsesTable, CachedResponse, $$CachedResponsesTableFilterComposer, $$CachedResponsesTableOrderingComposer, $$CachedResponsesTableAnnotationComposer, $$CachedResponsesTableCreateCompanionBuilder, $$CachedResponsesTableUpdateCompanionBuilder, (CachedResponse, BaseReferences<_$DataBase, $CachedResponsesTable, CachedResponse>), CachedResponse, PrefetchHooks Function()>
$$CachedResponsesTableUpdateCompanionBuilder = CachedResponsesCompanion Function({Value<DateTime> cachedAt, Value<String> requestKey, Value<String> responseData, Value<int> rowid})
$$ServicesTableCreateCompanionBuilder = ServicesCompanion Function({Value<String?> created, required Map<String, dynamic> data, Value<String> id, Value<int> rowid, required String service, Value<String?> updated})
$$ServicesTableProcessedTableManager = ProcessedTableManager<_$DataBase, $ServicesTable, Service, $$ServicesTableFilterComposer, $$ServicesTableOrderingComposer, $$ServicesTableAnnotationComposer, $$ServicesTableCreateCompanionBuilder, $$ServicesTableUpdateCompanionBuilder, (Service, $$ServicesTableReferences), Service, PrefetchHooks Function({bool blobFilesRefs})>
$$ServicesTableUpdateCompanionBuilder = ServicesCompanion Function({Value<String?> created, Value<Map<String, dynamic>> data, Value<String> id, Value<int> rowid, Value<String> service, Value<String?> updated})
$TextEntriesCreateCompanionBuilder = TextEntriesCompanion Function({required String data, Value<int> rowid})
$TextEntriesProcessedTableManager = ProcessedTableManager<_$DataBase, TextEntries, TextEntry, $TextEntriesFilterComposer, $TextEntriesOrderingComposer, $TextEntriesAnnotationComposer, $TextEntriesCreateCompanionBuilder, $TextEntriesUpdateCompanionBuilder, (TextEntry, BaseReferences<_$DataBase, TextEntries, TextEntry>), TextEntry, PrefetchHooks Function()>
$TextEntriesUpdateCompanionBuilder = TextEntriesCompanion Function({Value<String> data, Value<int> rowid})
ClearFunc = Future<void> Function()
ListItemFactory<M extends Jsonable> = M Function(Map<String, dynamic> item)
The factory function (eg. fromJson()) that will be used for a single item in a paginated list.
OAuth2URLCallbackFunc = void Function(Uri url)
RecordSubscriptionFunc = void Function(RecordSubscriptionEvent e)
The definition of a realtime record subscription callback function.
SaveFunc = Future<void> Function(String data)
SubscriptionFunc = void Function(SseMessage e)
The definition of a realtime subscription callback function.
UnsubscribeFunc = Future<void> Function()

Exceptions / Errors

ClientException
An exception caused by an error in the PocketBase client.