useFunctionsEmulator method

void useFunctionsEmulator({
  1. required String origin,
})

Changes this instance to point to a Cloud Functions emulator running locally.

Set the origin of the local emulator, such as "http://localhost:5001", or null to remove.

Implementation

void useFunctionsEmulator({required String origin}) {
  assert(origin.isNotEmpty);

  // Android considers localhost as 10.0.2.2 - automatically handle this for users.
  if (!kIsWeb && defaultTargetPlatform == TargetPlatform.android) {
    if (origin.startsWith('http://localhost')) {
      _origin = origin.replaceFirst('http://localhost', 'http://10.0.2.2');
      return;
    }
    if (origin.startsWith('http://127.0.0.1')) {
      _origin = origin.replaceFirst('http://127.0.0.1', 'http://10.0.2.2');
      return;
    }
  }

  _origin = origin;
}