🔥 Lesson

Hello World Android Flutter App Connected to Firebase

Build a beginner-friendly Flutter Android app, connect it to Firebase using FlutterFire CLI, initialize Firebase in code, and display a success message on screen.

Level: Beginner Platform: Android Tool: Flutter Backend: Firebase Method: FlutterFire CLI

What you will build

  • A Flutter Android project
  • A Firebase project
  • A Firebase-connected Flutter app
  • A working Hello World screen
  • A simple Firebase initialization test

App Name Setup Generator

Enter your Flutter app name. The lesson will automatically update project commands, package name, Firebase app name, and code examples.

Generated Details

Project: hello_firebase_app

Package: com.example.hello_firebase_app

Title: Hello Firebase App

Tip: Use a simple name like Student Attendance App. The system will convert it into Flutter-safe names automatically.

Flutter

Flutter builds the mobile app interface using Dart.

Firebase

Firebase gives backend services like authentication, database, storage, hosting, analytics, and notifications.

Android

We will run this app on an Android emulator or a real Android phone.

1

Create a New Flutter Project

Open terminal and run:

flutter create hello_firebase_app
cd hello_firebase_app
This creates a fresh Flutter app named hello_firebase_app.
2

Create a Firebase Project

Open Firebase Console and create a new project. You can name it Hello Firebase App.


Simple idea: Firebase project is the backend home of your app.
3

Find Your Android Package Name

Firebase asks for the Android package name. For this lesson, your generated package name is:

com.example.hello_firebase_app

Where to check it?

For older Flutter projects

Open this file:

android/app/build.gradle

Look for:

applicationId "com.example.hello_firebase_app"
For newer Flutter projects

Open this file:

android/app/build.gradle.kts

Look for:

applicationId = "com.example.hello_firebase_app"
Important: The package name in Firebase must match your Android app package name exactly.
4

Recommended Modern Firebase Setup

The modern FlutterFire method is best because it creates firebase_options.dart automatically.

Install Firebase Core

flutter pub add firebase_core

Install FlutterFire CLI

dart pub global activate flutterfire_cli

Configure Firebase

flutterfire configure
After this command, FlutterFire should create lib/firebase_options.dart.
5

Optional Manual Android Setup

Use this only if you are following the manual Firebase Android method.

Download this file from Firebase:

google-services.json

Place it here:

android/app/google-services.json
For beginners, prefer the FlutterFire CLI method in Step 4. It is cleaner and reduces manual mistakes.
6

Adding Firebase to an Existing Flutter App

If your Flutter app already exists, do not create a new app. Open your existing app folder and run the Firebase setup commands there.

Go to your app folder

cd your_existing_flutter_app

Add Firebase Core

flutter pub add firebase_core

Install and run FlutterFire CLI

dart pub global activate flutterfire_cli
flutterfire configure

Clean and run

flutter clean
flutter pub get
flutter run
Success check: If your old app opens without Firebase error, Firebase has been added successfully.
7

Complete main.dart Code

Replace lib/main.dart with this:

8

Run the App

Connect your Android phone or open an emulator, then run:

flutter run
Expected output: Hello Firebase App

Very Simple Explanation

main()

The app starts from here.

WidgetsFlutterBinding

Prepares Flutter before Firebase starts.

Firebase.initializeApp()

Connects the app to Firebase.

firebase_options.dart

Stores Firebase configuration generated by FlutterFire CLI.

MaterialApp

Creates the base Flutter app.

Firebase.apps.length

Checks how many Firebase apps are initialized.

Setup Checklist

Common Errors and Fixes

Firebase has not been correctly initialized

Fix: Make sure Firebase.initializeApp() is called before runApp().

firebase_options.dart not found

Fix: Run:

flutterfire configure
FlutterFire command not found

Fix: Install or reactivate FlutterFire CLI:

dart pub global activate flutterfire_cli
App builds but Firebase does not work

Fix: Check that your Firebase Android package name exactly matches your Flutter Android application ID.

Gradle or Android build error

Try:

flutter clean
flutter pub get
flutter run

MCQ Quiz

1. Which package is required to initialize Firebase in Flutter?


2. Which function connects Flutter with Firebase?


3. Which command runs the Flutter app?


4. Which file is generated by FlutterFire CLI?

DartPad Practice Area

Use DartPad for quick Dart and Flutter practice in the browser. For full Firebase setup, use your local Flutter installation because Firebase Android setup needs project files and Gradle configuration.

Official Installation and Setup Links

Install Flutter

Download and install the Flutter SDK from the official documentation.

Open Flutter Install Guide

Install Android Studio

Install Android Studio for Android SDK, emulator, and device tools.

Open Android Studio Download

Firebase Console

Create your Firebase project and manage app configuration.

Open Firebase Console

FlutterFire Setup

Official guide for connecting Firebase with Flutter.

Open FlutterFire Setup

DartPad

Practice Dart and Flutter online without installing anything.

Open DartPad

FlutterFire Overview

Learn how Firebase plugins work with Flutter apps.

Open FlutterFire Overview

Next Upgrade Ideas

Firebase Authentication

Add email/password login or Google login.

Cloud Firestore

Save student records, notes, or course progress.

Firebase Storage

Upload images, PDFs, and student files.

Push Notifications

Send class updates and reminders.

⚡ CLI Guide