Adding Flutter projects with Firebase using Flutterfire CLI

Connection between server and database is one of the important part of the any applications. Firebase is one of the backend cloud computing and application development platform provided by Google. It host database, services, authentications for variety of application includes android, iOS, javaScript, unity , C++ and many more. Firebase is designed to be easy to use and handles much of infrastructures, allowing users to focus on building frontend.

Adding Flutter projects on to firebase is one of the important things during the development process. Generally it is easy to add the flutter to the firebase but sometimes it may be time consuming and make confusion between the codes. Flutterfire CLI is a useful tools which provide commands that help ease the installation process of FlutterFire across all supported platforms.

Inside the Firebase console, go to project you want. If you haven't create a project then create a project. After you inside a project, go to to Project Overview and click on the flutter logo as shown on the image below.

When you click on that flutter logo you will be navigate to the next page that is shown below.

Follow the process i.e. login from a terminal. You can use command prompt(cmd) and run as administrator. Copy the code "firebase login" and run it. It may ask to login the the firebase again. No need to run "flutter create" because you have already create a project. If not create then create one. Click on Next.

Run the command "dart pub global activate flutterfire_cli" from any terminal. You can use command prompt(cmd). After you run the first command, now run the second command " flutterfire configure --project=Your project". Your command should match with the code given by the flutterfire. You should run the second command from the same terminal you use in the project you want to connect flutter with firebase. Now you should something like in the image below.

You have to select which platform your configuration to support. If you are using android then use space to select. After you select the platform flutterfire will automatically confirgure you settings.

At last you have to configure some code inside main.dart.

Future<void> main() async {

  WidgetsFlutterBinding.ensureInitialized(); //add this code

  // add this code  
  await Firebase.initializeApp( 
    options: DefaultFirebaseOptions.currentPlatform,
  );
  runApp(const MyApp());
}

And you are ready to go.

0
Subscribe to my newsletter

Read articles from Prabesh Bhattarai directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Prabesh Bhattarai
Prabesh Bhattarai