$PocketBase class
- Inheritance
-
- Object
- PocketBase
- $PocketBase
- Mixed-in types
Constructors
- $PocketBase(String baseUrl, {required DataBase db, Duration? cacheTtl = const Duration(days: 60), RequestPolicy requestPolicy = RequestPolicy.cacheAndNetwork, int localSyncRetryCount = 5, Duration? requestTimeout = const Duration(seconds: 15), int? maxFileCacheBytes = defaultMaxFileCacheBytes, Duration connectivityProbeTimeout = const Duration(seconds: 5), Duration connectivityOnlineProbeInterval = const Duration(seconds: 60), Duration connectivityOfflineBackoffMin = const Duration(seconds: 5), Duration connectivityOfflineBackoffMax = const Duration(seconds: 60), String lang = "en-US", AuthStore? authStore, Client httpClientFactory()?})
- $PocketBase.database(String baseUrl, {bool inMemory = false, String lang = "en-US", $AuthStore? authStore, DatabaseConnection? connection, String dbName = 'pb_drift.db', Duration? cacheTtl = const Duration(days: 60), RequestPolicy requestPolicy = RequestPolicy.cacheAndNetwork, Client httpClientFactory()?, int localSyncRetryCount = 5, Duration? requestTimeout = const Duration(seconds: 15), int? maxFileCacheBytes = defaultMaxFileCacheBytes, Duration connectivityProbeTimeout = const Duration(seconds: 5), Duration connectivityOnlineProbeInterval = const Duration(seconds: 60), Duration connectivityOfflineBackoffMin = const Duration(seconds: 5), Duration connectivityOfflineBackoffMax = const Duration(seconds: 60)})
-
factory
Properties
- admins → RecordService
-
no setterinherited
- authStore ↔ AuthStore
-
An instance of the local AuthStore service.
latefinalinherited
- backups ↔ BackupService
-
The service that handles the Backup and restore APIs.
latefinalinherited
- baseURL ↔ String
-
The PocketBase backend base url address (eg. 'http://127.0.0.1:8090').
getter/setter pairinherited
- baseUrl ↔ String
-
getter/setter pairinherited
- cacheTtl → Duration?
-
The time-to-live duration for cached records and responses.
Records and responses older than this will be cleaned up when
runMaintenance is called. Default is 60 days.
final
- collections ↔ $CollectionService
-
An instance of the service that handles the Collection APIs.
getter/setter pairinherited-setteroverride-getter
- connectivity ↔ ConnectivityService
-
latefinal
- crons ↔ CronService
-
The service that handles the Cron APIs.
latefinalinherited
- db → DataBase
-
final
- files ↔ $FileService
-
One instance per client, so concurrent downloads of a file are shared.
getter/setter pairinherited-setteroverride-getter
- hasExpiredSession → bool
-
Whether the auth store holds a token that is no longer valid: expired
by its
expclaim, the rule ofauthStore.isValid. An empty token (a guest) is not an expired session.no setter - hashCode → int
-
The hash code for this object.
no setterinherited
- health ↔ HealthService
-
An instance of the service that handles the Health APIs.
latefinalinherited
- httpClientFactory ↔ Client Function()
-
The HTTP clients of this instance hand out the realtime (SSE)
response through a stream
_restartRealtimecan end.getter/setter pairinherited-setteroverride-getter - lang ↔ String
-
Optional language code (default to
en-US) that will be sent with the requests to the server asAccept-Languageheader.getter/setter pairinherited - localSyncRetryCount → int
-
How many times the server may reject a pending local change (e.g. a
400 validation error) before automatic sync stops retrying it.
final
- logger → Logger
-
final
- logging ← bool
-
no getter
- logs ↔ LogService
-
An instance of the service that handles the Log APIs.
latefinalinherited
- maxFileCacheBytes → int?
-
Size limit in bytes of the file blob cache: downloaded files, thumbs
and the cached copies of uploaded files.
final
-
onSessionExpired
→ Stream<
void> -
Emits when the package first skips server work because the session
expired (see hasExpiredSession), for example to ask the user to log
in again. It emits again only after an auth change that leaves a
valid token. A skip without listeners is not reported, so check
hasExpiredSession when you start listening.
no setter
- realtime ↔ RealtimeService
-
An instance of the service that handles the Realtime APIs.
latefinalinherited
- realtimeHub → RealtimeHub
-
Shares realtime subscriptions between live queries (internal).
latefinal
- realtimeMatchesSession → bool
-
Whether realtime events may reach the cache: the realtime connection
is a guest or authenticated as the account logged in now. After a
logout or an account switch it keeps the previous account's auth until
it reconnects, and that account's records must not show up for the
next user.
no setter
- requestPolicy → RequestPolicy
-
The default RequestPolicy to use for all service methods.
final
- requestTimeout → Duration?
-
Maximum time for a single record request (reads of one record and
writes without file uploads). When it elapses, offline-first writes
are queued for sync and reads fall back to the cache.
nulldisables the limit. List reads use their owntimeoutargument.final - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- settings ↔ SettingsService
-
An instance of the service that handles the Settings APIs.
latefinalinherited
- sql ↔ SQLService
-
The service that handles the SQL APIs.
latefinalinherited
-
syncCompleted
→ Future<
void> -
Completes when the running sync pass (if any) ends. Never throws.
no setter
-
syncFailures
→ Stream<
SyncFailure> -
Pending local changes the server rejected for good, or updates whose
record was deleted on the server (see SyncFailure.dropped).
no setter
Methods
-
$collection(
String collectionIdOrName, {RequestPolicy requestPolicy = RequestPolicy.cacheAndNetwork}) → Future< $RecordService> - Get a collection by id or name and fetch the scheme to set it locally for use in validation and relations.
-
$createBatch(
) → $BatchService - Creates a new batch service for executing transactional batch operations.
-
buildURL(
String path, [Map< String, dynamic> queryParameters = const {}]) → Uri -
Builds and returns a full request url by safely concatenating
the provided path to the base url.
inherited
-
buildUrl(
String path, [Map< String, dynamic> queryParameters = const {}]) → Uri -
inherited
-
checkExpiredSession(
) → bool -
Returns hasExpiredSession and reports the first
trueon onSessionExpired. Used by the services where they skip server work. -
close(
) → void -
Note: this method needs to be called only when the PocketBase
client instance is created with the
reuseHTTPClientoption.override -
collection(
String collectionIdOrName) → $RecordService -
Returns the RecordService associated to the specified collection.
override
-
createBatch(
) → BatchService -
Creates a new batch handler for sending multiple transactional
create/update/upsert/delete collection requests in one network call.
inherited
-
didChangeAccessibilityFeatures(
) → void -
Called when the system changes the set of currently active accessibility
features.
inherited
-
didChangeAppLifecycleState(
AppLifecycleState state) → void -
Called when the system puts the app in the background or returns
the app to the foreground.
override
-
didChangeLocales(
List< Locale> ? locales) → void -
Called when the system tells the app that the user's locale has
changed. For example, if the user changes the system language
settings.
inherited
-
didChangeMetrics(
) → void -
Called when the application's dimensions change. For example,
when a phone is rotated.
inherited
-
didChangePlatformBrightness(
) → void -
Called when the platform brightness changes.
inherited
-
didChangeTextScaleFactor(
) → void -
Called when the platform's text scale factor changes.
inherited
-
didChangeViewFocus(
ViewFocusEvent event) → void -
Called whenever the PlatformDispatcher receives a notification that the
focus state on a view has changed.
inherited
-
didHaveMemoryPressure(
) → void -
Called when the system is running low on memory.
inherited
-
didPopRoute(
) → Future< bool> -
Called when the system tells the app to pop the current route, such as
after a system back button press or back gesture.
inherited
-
didPushRoute(
String route) → Future< bool> -
Called when the host tells the application to push a new route onto the
navigator.
inherited
-
didPushRouteInformation(
RouteInformation routeInformation) → Future< bool> -
Called when the host tells the application to push a new
RouteInformation and a restoration state onto the router.
inherited
-
didRequestAppExit(
) → Future< AppExitResponse> -
Called when a request is received from the system to exit the application.
inherited
-
discardPendingChange(
String collectionIdOrName, String id) → Future< void> -
Drops the pending local change of
collectionIdOrName/id(for example one the server rejected). The cached row is removed, so the next read loads the server's version. -
enforceFileCacheLimit(
) → Future< void> - Applies maxFileCacheBytes; the package calls it after each blob write. Concurrent calls share one run; a call during a run schedules one more run.
-
filter(
String expr, [Map< String, dynamic> params = const {}]) → String -
Constructs a filter expression with placeholders populated from a map.
inherited
-
fitsFileCache(
int bytes) → bool -
Whether a file of
bytesthat the server can send again goes into the file cache: with a limit, only up to the eviction target (90% of maxFileCacheBytes); a larger file would push out every other file. Unsynced uploads are always stored. -
getFileUrl(
RecordModel record, String filename, {String? thumb, String? token, Map< String, dynamic> query = const {}}) → Uri -
inherited
-
handleCancelBackGesture(
) → void -
Called when a predictive back gesture is canceled, indicating that no
navigation should occur.
inherited
-
handleCommitBackGesture(
) → void -
Called when a predictive back gesture is finished successfully, indicating
that the current route should be popped.
inherited
-
handleStartBackGesture(
PredictiveBackEvent backEvent) → bool -
Called at the start of a predictive back gesture.
inherited
-
handleStatusBarTap(
) → void -
Called when the user taps the status bar on iOS, to scroll a scroll
view to the top.
inherited
-
handleUpdateBackGestureProgress(
PredictiveBackEvent backEvent) → void -
Called when a predictive back gesture moves.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
reportSyncFailure(
SyncFailure failure) → void -
Emits
failureon syncFailures. Used by the services. -
runMaintenance(
{Duration? ttl}) → Future< MaintenanceResult> - Runs maintenance tasks to clean up expired cached data.
-
search(
String query, {String? service}) → Selectable< Service> -
send<
T extends dynamic> (String path, {String method = "GET", Map< String, String> headers = const {}, Map<String, dynamic> query = const {}, Map<String, dynamic> body = const {}, List<MultipartFile> files = const [], RequestPolicy requestPolicy = RequestPolicy.cacheAndNetwork}) → Future<T> -
Sends a single HTTP request with offline caching capabilities.
override
-
setSchema(
String jsonSchema) → Future< void> -
Caches the collection definitions (
pb_schema.jsoncontent) used for validation, relation expansion and file fields. -
syncPendingChanges(
{bool includeFailed = false}) → Future< void> - Pushes all pending local changes to the server.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Constants
- defaultMaxFileCacheBytes → const int
- Default of maxFileCacheBytes: 128 MB, 32 MB on the web (where the IndexedDB storage fallback keeps the whole database in memory).