initialize static method
Initializes Firebase with the specified configurations.
This method must be called before any other Firebase operation.
Parameters:
apiKey
: Firebase API key for your projectauthDomain
: Firebase authentication domainprojectId
: Firebase project IDstorageBucket
: Firebase storage bucketmessagingSenderId
: Firebase Cloud Messaging sender IDappId
: Firebase application IDisDev
: Iftrue
, Firebase Auth will use the local emulator on localhost:9099. Defaults tofalse
.
Examples:
// Production environment initialization
await SFFirebaseAuth.initialize(
apiKey: 'AIzaSyD_example_key',
authDomain: 'my-app.firebaseapp.com',
projectId: 'my-app',
storageBucket: 'my-app.appspot.com',
messagingSenderId: '1234567890',
appId: '1:1234567890:web:abcdef1234567890',
);
// Development environment with emulator
await SFFirebaseAuth.initialize(
apiKey: 'demo-key',
authDomain: 'localhost',
projectId: 'demo-project',
storageBucket: '',
messagingSenderId: '',
appId: '',
isDev: true,
);
Implementation
static Future<void> initialize({
required String apiKey,
required String authDomain,
required String projectId,
required String storageBucket,
required String messagingSenderId,
required String appId,
bool isDev = false,
}) async {
await Firebase.initializeApp(
options: FirebaseOptions(
apiKey: apiKey,
authDomain: authDomain,
projectId: projectId,
storageBucket: storageBucket,
messagingSenderId: messagingSenderId,
appId: appId,
),
);
if (isDev) {
await FirebaseAuth.instance.useAuthEmulator('localhost', 9099);
FirebaseFunctions.instance.useFunctionsEmulator('localhost', 5001);
FirebaseFirestore.instance.useFirestoreEmulator('localhost', 8080);
FirebaseStorage.instance.useStorageEmulator('localhost', 9199);
}
}