withEmulator method
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.
mockUserToken authenticates the requests to the emulator, see
Settings.mockUserToken. Like connectFirestoreEmulator, the
emulator options replace the previous ones: without mockUserToken the
copy has none.
Throws an ArgumentError when host is the production host
(defaultHost).
final FirebaseFirestore firestore = FirebaseFirestore.instanceFor(
app: app,
settings: Settings().withEmulator(
'127.0.0.1',
8080,
mockUserToken: {'sub': 'alice'},
),
);
Implementation
Settings withEmulator(String host, int port, {Object? mockUserToken}) {
if (_isProductionHost(host)) {
throw ArgumentError.value(
host,
'host',
'The production host is not an emulator',
);
}
return _copy(
host: host,
port: port,
sslEnabled: false,
emulator: true,
mockUserToken: mockUserToken,
);
}