useEmulator method Null safety

  1. @Deprecated('Will be removed in future release. ' 'Use useAuthEmulator().')
Future<void> useEmulator(
  1. String origin
@Deprecated('Will be removed in future release. ' 'Use useAuthEmulator().')

Changes this instance to point to an Auth emulator running locally.

Set the origin of the local emulator, such as "http://localhost:9099"

Note: Must be called immediately, prior to accessing auth methods. Do not use with production credentials as emulator traffic is not encrypted.

Note: auth emulator is not supported for web yet. firebase-js-sdk does not support auth.useEmulator until v8.2.4, but FlutterFire does not support firebase-js-sdk v8+ yet


  'Will be removed in future release. '
  'Use useAuthEmulator().',
Future<void> useEmulator(String origin) async {
  String mappedOrigin = origin;

  // Android considers localhost as - automatically handle this for users.
  if (defaultTargetPlatform == && !kIsWeb) {
    if (mappedOrigin.startsWith('http://localhost')) {
      mappedOrigin =
          mappedOrigin.replaceFirst('http://localhost', '');
    } else if (mappedOrigin.startsWith('')) {
      mappedOrigin =
          mappedOrigin.replaceFirst('', '');

  // Native calls take the host and port split out
  final hostPortRegex = RegExp(r'^http:\/\/([\w\d.]+):(\d+)$');
  final RegExpMatch? match = hostPortRegex.firstMatch(mappedOrigin);
  if (match == null) {
    throw ArgumentError('firebase.auth().useEmulator() origin format error');
  // Two non-empty groups in RegExp match - which is null-tested - these are non-null now
  final String host =!;
  final int port = int.parse(!);

  await useAuthEmulator(host, port);