initializeApp static method
Future<FirebaseApp>
initializeApp({
- String? name,
- FirebaseOptions? options,
- String? demoProjectId,
Initializes a new FirebaseApp instance by name
and options
and returns
the created app. This method should be called before any usage of FlutterFire plugins.
The default app instance can be initialized here simply by passing no "name" as an argument
in both Dart & manual initialization flows.
If you have a google-services.json
file in your android project or a GoogleService-Info.plist
file in your iOS+ project,
it will automatically create a default (named "DEFAULT
") app instance on the native platform. However, you will still need to call this method
before using any FlutterFire plugins.
Implementation
static Future<FirebaseApp> initializeApp({
String? name,
FirebaseOptions? options,
String? demoProjectId,
}) async {
if (demoProjectId != null) {
late final String platformString;
if (defaultTargetPlatform == TargetPlatform.android) {
platformString = 'android';
} else if (defaultTargetPlatform == TargetPlatform.iOS ||
defaultTargetPlatform == TargetPlatform.macOS) {
platformString = 'ios';
} else {
// We use 'web' as the default platform for unknown platforms.
platformString = 'web';
}
FirebaseAppPlatform app = await _delegate.initializeApp(
options: FirebaseOptions(
apiKey: '',
appId: '1:1:$platformString:1',
messagingSenderId: '',
projectId: demoProjectId,
),
);
return FirebaseApp._(app);
}
FirebaseAppPlatform app = await _delegate.initializeApp(
name: name,
options: options,
);
return FirebaseApp._(app);
}