16th Feb 2024
u/monzim
In this lesson, we are going to learn how we can add Firebase to our flutter application. And we are going the follow the official documentation.
# create a flutter app run this command
flutter create app_name --org com.YOUR_ORG_NAME
Visit the Firebase Console and log in with your Google account. Optionally, create a new project with a unique name.
Open your Flutter project in your preferred IDE (e.g., VSCode).
Make sure you have the following installed:
Already setup firebase and flutterfire cli then skips (1.0-2.0)
# To follow the next Step you must npm or yarn installs your system. (install npm)
npm install -g firebase-tools
For Linux:
curl -sL https://firebase.tools | bash
Log in to your account with Firebase CLI:
firebase login
It will open a new tab in chrome select the account and give the permission. If you successfully log in then flow to the next step.
dart pub global activate flutterfire_cli
Open your project in VSCode and navigate to the root directory. Run the following commands in the terminal:
From your Flutter project directory, run the following command to install the core plugin:
flutter pub add firebase_core
Ensure your Flutter app's Firebase configuration is up-to-date
flutterfire configure
In your lib/main.dart
file, import the Firebase core plugin and the configuration file you generated earlier:
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';
Also in your lib/main.dart
file, initialize Firebase using the DefaultFirebaseOptions
object exported by the configuration file:
await Firebase.initializeApp(
options: DefaultFirebaseOptions.currentPlatform,
);
Rebuild your Flutter application:
flutter run
For more details, refer to the official Firebase CLI documentation and Flutter setup guide.