coiai Logo

This article is an English translation of the original Japanese post. Read the Japanese original →

Using Firebase with Flutter: A Command Walkthrough

October 25, 2024

Categories: Flutter · Tags: firebase, Flutter, プログラミング

What is this?

A rundown of the commands you'll need to use Firebase in a Flutter project.

Environment

  • Apple Silicon M1 MacBook Air
  • macOS
  • firebase cli version 13.23.0
  • Flutter version 3.24.4

Steps

1. Create a project

Head over to the Firebase console and create a project.

https://console.firebase.google.com

firebase

2. Set up the Firebase CLI

This varies depending on your environment, so follow the official guide for your setup.

3. Initial CLI steps

firebase login

This command opens your browser, where you'll pick a Google account and confirm the requested permissions.

firebase projects:list

Try running the command above to double-check that you're logged in.
You should see the project name and project ID you created in step 1. Copy the Project ID, since you'll need it later.

4. Configure Flutter

First, move into your Flutter project's directory.

cd あなたのFlutterプロジェクトのディレクトリ

Next, run the following command to add the package.

flutter pub add firebase_core

Then run this command.

dart pub global activate flutterfire_cli

After running this, you'll need to add it to your PATH.
If you're on an Apple Silicon Mac, your terminal is probably running zsh, so run the command below.

echo 'export PATH="$PATH:$HOME/.pub-cache/bin"' >> ~/.zshrc

Once that's done, run the following command to load the zsh settings you just saved into your terminal.

source ~/.zshrc

Finally, run the command below. Replace [the ID you copied earlier] with your own ID.

flutterfire configure --project=さっきコピーしたID

When you run it, you'll see

✔ Which platforms should your configuration support

This is asking which platforms you want to use.
Press space to uncheck a platform.
If you want to use all of them, just press Enter to move on.

Next you'll see

? Which Android application id (or package name) do you want to use for this configuration, e.g. ‘com.example.app’?

This is asking for your Android build ID. Something like com.yourname.appname works fine.

That's it — Firebase is now ready to use in Flutter.
Nice work!

Using Firebase with Flutter: A Command Walkthrough | coiai Inc.