Flutter - Firebase Setup

Getting started

It used to be somewhat challenging to configure [[Firebase]] and [[../../../_notes/_tech/Flutter/Flutter]]. Now though they’ve provided a new flutterfire CLI to assist and it’s super easy now.

Install it with

npm install -g firebase-tools
dart pub global activate flutterfire_cli

Configure your project

Create a new flutter project and configure it with the command line


flutter create testapp
cd testapp

flutter pub add firebase_core

flutterfire configure

This step creates the config in firebase for your platform and puts the related config in a firebase_options.dart file.

Initialize the app

Open main.dart

Add the imports

import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';

and update the main function to the following

void main() async {
	WidgetsFlutterBinding.ensureInitialized();
	await Firebase.initializeApp(
		options: DefaultFirebaseOptions.currentPlatform,
	);
	runApp(MyApp());
}

Issues

After running flutter clean && flutter pub get then trying to run a mac build I received this error:

 Error output from CocoaPods: ↳ Searching for inspections failed: undefined method `map' for nil:NilClass Exception: Error running pod install

I found this fix on stack overflow

sudo arch -x86_64 gem install ffi
# go to ios folder then run
arch -x86_64 pod install
  • [[Flutter - Connecting to Firestore]]
  • [[flutter-firebase-auth-setup-for-android]]