copyWith method

Settings copyWith({
  1. String? host,
  2. int? port,
  3. bool? sslEnabled,
  4. bool? persistenceEnabled,
  5. int? cacheSizeBytes,
  6. LocalCacheSettings? cacheSettings,
  7. bool? webExperimentalForceLongPolling,
  8. bool? webExperimentalAutoDetectLongPolling,
  9. WebExperimentalLongPollingOptions? webExperimentalLongPollingOptions,
  10. int? grpcFlowControlWindow,
})

Returns a copy of these settings with the given values replaced; a null argument keeps the current value.

The values are checked as in the constructor. Turning one long-polling option on turns the other off unless both are given. Settings made by withEmulator keep their mockUserToken while the host, the port and the SSL setting stay those of the emulator; changing one of them on settings that have a token throws an ArgumentError.

final Settings base = Settings();
final Settings memory = base.copyWith(
  cacheSettings: const MemoryCacheSettings(),
);

Implementation

Settings copyWith({
  String? host,
  int? port,
  bool? sslEnabled,
  bool? persistenceEnabled,
  int? cacheSizeBytes,
  LocalCacheSettings? cacheSettings,
  bool? webExperimentalForceLongPolling,
  bool? webExperimentalAutoDetectLongPolling,
  WebExperimentalLongPollingOptions? webExperimentalLongPollingOptions,
  int? grpcFlowControlWindow,
}) {
  // The settings stay emulator settings (and keep their mock user token)
  // only while they point at the same emulator. Changing the host of
  // settings that have a token is an error: see [_checkMockUserToken].
  final bool emulator =
      _emulator &&
      (host ?? this.host) == this.host &&
      (port ?? this.port) == this.port &&
      !(sslEnabled ?? this.sslEnabled);
  return _copy(
    host: host,
    port: port,
    sslEnabled: sslEnabled,
    persistenceEnabled: persistenceEnabled,
    cacheSizeBytes: cacheSizeBytes,
    cacheSettings: cacheSettings,
    experimentalForceLongPolling: webExperimentalForceLongPolling,
    experimentalAutoDetectLongPolling: webExperimentalAutoDetectLongPolling,
    experimentalLongPollingOptions: webExperimentalLongPollingOptions,
    grpcFlowControlWindow: grpcFlowControlWindow,
    emulator: emulator,
    mockUserToken: mockUserToken,
  );
}