useFirestoreEmulator method
Changes this instance to point to a FirebaseFirestore emulator running locally.
Set the host
of the local emulator, such as "localhost"
Set the port
of the local emulator, such as "8080" (port 8080 is default)
Note: Must be called immediately, prior to accessing FirebaseFirestore methods. Do not use with production credentials as emulator traffic is not encrypted.
Implementation
void useFirestoreEmulator(String host, int port, {bool sslEnabled = false}) {
if (kIsWeb) {
// use useEmulator() API for web as settings are set immediately unlike native platforms
_delegate.useEmulator(host, port);
} else {
String mappedHost = host;
// Android considers localhost as 10.0.2.2 - automatically handle this for users.
if (!kIsWeb && defaultTargetPlatform == TargetPlatform.android) {
if (mappedHost == 'localhost' || mappedHost == '127.0.0.1') {
// ignore: avoid_print
print('Mapping Firestore Emulator host "$mappedHost" to "10.0.2.2".');
mappedHost = '10.0.2.2';
}
}
_delegate.settings = _delegate.settings.copyWith(
// "sslEnabled" has to be set to false for android to work
sslEnabled: sslEnabled,
host: '$mappedHost:$port',
);
}
}