Week 5 Day 07 Hospitality Domain Generated by Gemini Code Assist

Infrastructure Setup & Deployment

Comprehensive guide to setting up the GCP and Firebase environment for the Variance Analysis application.

1

Create GCP Project & Billing

The foundation of our cloud infrastructure starts with a Google Cloud Platform project.

  • Go to the GCP Console.
  • Click New Project and enter my-variance-analysis.
  • Navigate to Billing in the side menu.
  • Click Link a Billing Account to ensure the project can use paid services like Document AI and Firebase beyond free tiers.
2

Initialize Firebase

Firebase provides our real-time database, authentication, and hosting capabilities.

A. Create Firebase Project

Go to Firebase Console and click Add Project. Select your existing GCP project from the dropdown.

B. Database & Authentication

  • Firestore: Click "Create Database", choose "Production Mode", and select a region (e.g., us-central1).
  • Authentication: Enable "Email/Password" and "Google" sign-in providers under the Build > Authentication menu.
3

FlutterFire CLI Configuration

Modern Flutter development uses the CLI to automatically generate configuration files.

A. Prerequisites

Ensure you have the Firebase tools installed globally:

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

B. Configuration Command

Run this in your project root to fetch configs and generate code:

flutterfire configure

Select your project (my-variance-analysis) and platforms (Android, iOS) when prompted.

C. Generated Files

  • firebase_options.dart: Created in lib/. Contains API keys and app IDs for initializing Firebase in Dart code.
  • firebase.json: Created in project root. Maps your app services (Hosting, Functions, etc.) to the project.
4

Manual App Registration (Legacy/Alternative)

If not using the CLI, register your iOS and Android applications manually to receive configuration files.

Android Setup

Register package com.example.myvarianceanalysis and download google-services.json.

iOS Setup

Register bundle ID com.example.myvarianceanalysis and download GoogleService-Info.plist.

5

Manual Project File Integration

Correct placement of the .plist and .json files is critical if manually configuring.

iOS Integration (Xcode)

Move GoogleService-Info.plist into the ios/Runner directory. Important: You must open the project in Xcode, right-click the Runner folder, and select "Add Files to Runner" to ensure the file is linked to the build target.

Android Integration

Place google-services.json in the android/app/ directory.

6

Authentication Implementation

Integrating native login flows and user verification directly within the Flutter app.

A. Dependencies

Add these packages to your pubspec.yaml:

flutter pub add firebase_auth

B. Email/Password Authentication

Standard flow for creating and signing in users with email and password:

// Sign up a new user
try {
  final credential = await FirebaseAuth.instance.createUserWithEmailAndPassword(
    email: emailAddress,
    password: password,
  );
} on FirebaseAuthException catch (e) {
  if (e.code == 'weak-password') {
    print('The password provided is too weak.');
  } else if (e.code == 'email-already-in-use') {
    print('The account already exists for that email.');
  }
}

// Sign in existing user
try {
  final credential = await FirebaseAuth.instance.signInWithEmailAndPassword(
    email: emailAddress,
    password: password,
  );
} on FirebaseAuthException catch (e) {
  if (e.code == 'user-not-found') {
    print('No user found for that email.');
  } else if (e.code == 'wrong-password') {
    print('Wrong password provided for that user.');
  }
}

C. Email Verification

Send a verification email to the current user and check their status:

// Send verification email
await FirebaseAuth.instance.currentUser?.sendEmailVerification();

// Check verification status (reload user first)
await FirebaseAuth.instance.currentUser?.reload();
if (FirebaseAuth.instance.currentUser!.emailVerified) {
  print('User is verified');
}

Full Source Code & Infrastructure

The complete infrastructure-as-code (Terraform) for GCP creation and the full Flutter application source code is available on our GitLab repository.

View Project on GitLab

Visit this for detailed data on infrastructure creation and the final application implementation.