CLI
The FlutterFire CLI is a useful tool which provides commands to help ease the installation process of FlutterFire across all supported platforms.
Installation#
The FlutterFire CLI depends on the underlying Firebase CLI. If you haven't already done so, make sure you have the Firebase CLI installed on your machine. If not, make sure you have node.js on your machine and Install the Firebase CLI via npm by running the following command :
Learn more about the Firebase CLI in the documentation.
Next, install the FlutterFire CLI by running the following command:
Once installed, the flutterfire command will be globally available.
Usage#
note
Some plugins do not fully support Dart-only Firebase initialization, if you need to use these plugins then the manual installation steps are recommended.
The following table shows the current plugins with Dart-only Firebase initialization issues (plugins not shown here are fully supported):
- ? Indicates your app will build and run but plugin behavior may be different.
- โ Indicates your app will crash on startup without manual Google services PLIST/JSON file setup.
- โ Indicates no known issues.
Additionally, if you use the google_sign_in provider for Authentication in firebase_auth then this also requires manual installation. There is an open issue to move google_sign_in to Dart initialization which you can track here.
Generating Firebase Options#
note
If you initialize your Firebase app from Dart, you will likely receive warnings from the native Android & iOS Firebase SDKs indicating no Firebase app has been configured or
you don't have the relevant config file (i.e. GoogleService-Info.plist or google-services.json). You can safely ignore these warnings if
you're initializing your Firebase app from Dart.
FlutterFire can now be initialized from Dart on all platforms using Firebase.initializeApp, however
the options for different platforms can vary. The FlutterFire CLI can help, by generating a file
(by default called firebase_options.dart) which can be used when calling the initialization method.
The FlutterFire CLI extracts information from your Firebase project and selected project applications to generate all the configuration for a specific platform.
In the root of your application, run the configure command:
The configuration command will guide you through a number of processes:
- Selecting a Firebase project (based on the
.firebasercfile or from the Firebase Console). - Prompt what platforms (e.g. Android, iOS, macOS & web) you would like configuration for.
- Identify which Firebase applications for the chosen platforms should be used to extract configuration for. By default, the CLI will attempt to automatically match Firebase apps based on your current project configuration.
- Generate a
firebase_options.dartfile in your project.
Once complete, you can now import the generated file and provide it to the initializeApp method:
Then, provide the current platform options via the currentPlatform getter from the DefaultFirebaseOptions
class:
Commands#
Configure#
Generates a firebase_options.dart file which can be provided to the options parameter when
Initializing Firebase.
The command supports the following option arguments:
| Argument | Alias | Description |
|---|---|---|
| --project | -p | Sets the Firebase Project ID to use. By default, the CLI will attempt to fetch the project defined in the .firebaserc file, or prompt you to select the project from the Firebase Console. |
| --account | -e | Sets the email address which should be used to authenticate with Firebase against. By default, this will use the primary account defined on the Firebase CLI. |
| --out | -o | Specifies the path & file name for the generated file. Defaults to "lib/firebase_options.dart". |
| --ios-bundle-id | -i | The bundle identifier of your iOS app, e.g. "com.example.app". If no identifier is provided then an attempt will be made to automatically detect it from your "ios" folder (if it exists). |
| --macos-bundle-id | -m | The bundle identifier of your macOS app, e.g. "com.example.app". If no identifier is provided then an attempt will be made to automatically detect it from your "macos" folder (if it exists). |
| --android-app-id | -a | The application id of your Android app, e.g. "com.example.app". If no identifier is provided then an attempt will be made to automatically detect it from your "android" folder (if it exists). |
Version#
To view the current version of the FlutterFire CLI, run:
Reporting an issue#
If you have encountered any issues with the CLI, please report them here.