initFunctions function

void initFunctions({
  1. String region = '',
  2. String? app,
})

Prepares Functions on an app: the default one, or the named one app. initDatabase or initNamedApp must have made the app first.

region is spelled as the other SDKs spell it (us-central1 and so on); empty means us-central1. Each region is its own instance, so call this once per region the app uses. The first one initialized on an app is what an empty region means on it everywhere else.

Implementation

void initFunctions({String region = '', String? app}) {
  ensureLibraryLoaded();
  if (!hasFirebase) {
    throw StateError('this build has no Firebase SDK');
  }
  final r = region.toNativeUtf8();
  try {
    final rc = _onApp(app, (a) => fdbFunctionsInit(a, r.cast()));
    if (rc != 0) {
      throw StateError(
        rc != -1
            ? 'Functions instance could not be created ($rc)'
            : app == null || app.isEmpty
            ? 'initFunctions before the Firebase app was initialized'
            : 'initFunctions on "$app", which is not an app — call '
                  'initNamedApp first',
      );
    }
  } finally {
    calloc.free(r);
  }
}