Settings class

The settings of a FirebaseFirestore instance: the backend it talks to, its local cache and its transport options.

Pass them to FirebaseFirestore.instanceFor when you create the instance; they cannot change while the instance runs (a later instanceFor call with different settings throws a StateError). The settings are immutable: derive new ones with copyWith and withEmulator. Every argument is checked in the constructor, which throws an ArgumentError for an invalid value.

The defaults talk to production Firestore (defaultHost) over TLS, with a 100 MB cache that is persistent when instanceFor gets an openDatabase function and in memory otherwise.

final FirebaseFirestore firestore = FirebaseFirestore.instanceFor(
  app: app,
  settings: Settings(
    cacheSettings: PersistentCacheSettings(sizeBytes: 50 * 1024 * 1024),
  ),
);

// Against the emulator.
final Settings emulator = Settings().withEmulator(
  '127.0.0.1',
  8080,
);

Settings is an alias of this class.

Constructors

Settings({String host = defaultHost, int port = defaultPort, bool sslEnabled = true, bool persistenceEnabled = true, int cacheSizeBytes = defaultCacheSizeBytes, LocalCacheSettings? cacheSettings, bool webExperimentalForceLongPolling = false, bool? webExperimentalAutoDetectLongPolling, WebExperimentalLongPollingOptions webExperimentalLongPollingOptions = const WebExperimentalLongPollingOptions(), int grpcFlowControlWindow = defaultGrpcFlowControlWindow})
Creates settings; every argument has the default of the field of the same name.

Properties

cacheSettings → LocalCacheSettings?
Configures the local cache with PersistentCacheSettings or MemoryCacheSettings. It replaces persistenceEnabled and cacheSizeBytes: passing it together with a non default value of either throws a StateError. When null, the cache is configured by those two settings.
final
cacheSizeBytes → int
Sets an approximate cache size threshold for the on-disk data. If the cache grows beyond this size, Firestore will start removing data that hasn't been recently used. The size is not a guarantee that the cache will stay below that size, only that if the cache exceeds the given size, cleanup will be attempted.
final
grpcFlowControlWindow → int
The HTTP/2 flow-control window of the gRPC transport, in bytes: how much the backend may send on the connection, and on each request, before the client acknowledges it. Defaults to defaultGrpcFlowControlWindow (256 KiB); the HTTP/2 default is 64 KiB, which limits large reads on a connection with a long round trip time. Same as grpcFlowControlWindow of the Android and JS SDKs (in JS, Node only). Ignored by the web transport.
final
hashCode → int
The hash code for this object.
no setteroverride
host → String
The host of the Firestore backend, defaultHost by default.
final
mockUserToken → Object?
The token sent to the Firestore emulator to authenticate the requests, set with withEmulator (the only way to set it: it is never sent to a host that was not configured as an emulator). Same as the mockUserToken option of connectFirestoreEmulator in the JS SDK; meant for testing security rules, it replaces the token of Firebase Auth.
final
persistenceEnabled → bool
Enables or disables local persistent storage. The default is to use local persistent storage.
final
port → int
The port of the Firestore backend. Defaults to 443.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
sslEnabled → bool
Enables or disables SSL for communication. The default is to use SSL.
final
webExperimentalAutoDetectLongPolling → bool
Web only (ignored where the client uses gRPC): switch a stream to long polling when its first response does not arrive in time, which is how a buffering proxy shows. On by default, unless webExperimentalForceLongPolling is set. The option of the same name of the JS SDK has the same purpose but detects differently.
final
webExperimentalForceLongPolling → bool
Web only (ignored where the client uses gRPC): always use long polling for the listen and write streams, instead of a streamed HTTP response. For networks with a proxy or an antivirus that buffers responses, which otherwise shows as listeners and writes that never complete. Less efficient. Same as webExperimentalForceLongPolling of the JS SDK. Cannot be combined with webExperimentalAutoDetectLongPolling.
final
webExperimentalLongPollingOptions → WebExperimentalLongPollingOptions
Web only: options of long polling, see WebExperimentalLongPollingOptions. Same as webExperimentalLongPollingOptions of the JS SDK. Throws an ArgumentError when WebExperimentalLongPollingOptions.timeoutDuration is not between 5 and 30 seconds.
final

Methods

copyWith({String? host, int? port, bool? sslEnabled, bool? persistenceEnabled, int? cacheSizeBytes, LocalCacheSettings? cacheSettings, bool? webExperimentalForceLongPolling, bool? webExperimentalAutoDetectLongPolling, WebExperimentalLongPollingOptions? webExperimentalLongPollingOptions, int? grpcFlowControlWindow}) → Settings
Returns a copy of these settings with the given values replaced; a null argument keeps the current value.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
override
withEmulator(String host, int port, {Object? mockUserToken}) → Settings
Returns a copy that talks to the Firestore emulator listening on host and port, without SSL. Equivalent to useEmulator of the other SDKs; it has to be applied to the settings that are passed when the instance is created. A host that was set before is replaced.

Operators

operator ==(Object other) → bool
The equality operator.
override

Constants

cacheSizeUnlimited → const int
Constant to use with cacheSizeBytes to disable garbage collection.
defaultCacheSizeBytes → const int
The cache size threshold used when none is configured (100 MB).
defaultGrpcFlowControlWindow → const int
The default of grpcFlowControlWindow: 256 KiB, as in the Android and JS SDKs.
defaultHost → const String
The host of the production Firestore service.
defaultPort → const int
The port of the production Firestore service.
minimumCacheBytes → const int
The minimum cache size, 1 MB.