> For the complete documentation index, see [llms.txt](https://sumiths-organization.gitbook.io/flutterdevcamp-mentee-app/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sumiths-organization.gitbook.io/flutterdevcamp-mentee-app/add-firebase.md).

# Add Firebase

We will add Firebase to the code, Firebase is a BaaS (Backend-as-a-Service) offering a wide range of features that would be very complex to implement on your own.

Adding Firebase to a mobile or web app used to be a long and painful process.

Firebase CLI <https://firebase.google.com/docs/flutter/setup?platform=android>

```terminal
npm install -g firebase-tools
firebase login
dart pub global activate flutterfire_cli
export PATH="$PATH":"$HOME/.pub-cache/bin"
```

Use flutterfire CLI to either create a new Firebase project or use an existing

```
flutterfire configure
flutterfire configure --project=todo-flutter-8a80f
```

This will create a new file -> <mark style="color:green;">**firebase\_options.dart**</mark> and other files

```
lib/firebase_options.dart
ios/Runner/GoogleService-Info.plist
ios/firebase_app_id_file.json
macos/Runner/GoogleService-Info.plist
macos/firebase_app_id_file.json
android/app/google-services.json
```

Update pubspec.yaml with&#x20;

```yaml
firebase_core: ^2.25.4
```

We need to initialise firebase now

Modify MyApp class -> build method &#x20;

{% code lineNumbers="true" %}

```dart
Widget build(BuildContext context) {
    return FutureBuilder(
      future: Firebase.initializeApp(
        options: DefaultFirebaseOptions.currentPlatform,
      ),
      builder: (context, snapshot) {
        if (snapshot.connectionState == ConnectionState.done) {
          return const MaterialApp(
            debugShowCheckedModeBanner: false,
            home: 1 == 1 ? LoginScreen() : HomeScreen(),
          );
        } else {
          return MaterialApp(
            debugShowCheckedModeBanner: false,
            home: Scaffold(
              body: Container(),
            ),
          );
        }
      },
    );
  }
```

{% endcode %}

Run the App, **Restart**
