Skip to content

Software Development at Program Tom LTD

Place for coding, programming, development and software in general.

Menu
  • Blog
  • PDF Booklets
  • Dev Utils & Content
  • Java Spring Boot Or Web Apps
  • English
    • български
    • English
    • Español
    • Português
    • हिन्दी
    • Русский
    • Deutsch
    • Français
    • Italiano
    • العربية
  • About Us
Menu
Flutter Login Firebase Google

Flutter Android Login using Firebase & Google – from Scratch

Posted on April 18, 2021November 24, 2023 by Toma Velev

In this article I’m gonna detail the steps to implement Login with Firebase and Google from Scratch in Flutter Android. You could start by following that steps on: https://firebase.flutter.dev/docs/overview/.

Create new Flutter – Hello World – Project.

Nothing complex here. You could execute it from any of the IDEs or the command line “flutter create <project_name>”.

Add dependencies and Setup

In your pubspec.yaml file, in the “dependencies:” area, add

firebase_core: "^1.0.3" 
firebase_auth: "^1.1.0"
google_sign_in: ^5.0.0-nullsafety
  • Firebase_core is the basis that connects to Firebase and opens the possibilities to use any of the Cloud Services within your app.
  • Firebase_auth is the abstraction above all the ways a user could Authenticate against some service. It has methods for processing custom – new user registration and a common method for delegating Authentication to 3rd parties

For integrating Firebase Auth on Android, there are several more things to do:

    • Setup and Download your google-services.json – generated on the Firebase Cloud Console into <project>/android/ – folder.
    • You need to include the sha1 footprint in the Firebase Cloud Configuration: https://stackoverflow.com/questions/27609442/how-to-get-the-sha-1-fingerprint-certificate-in-android-studio-for-debug-mode.

 

  • In the android/build.gradle – add the following dependency:

 

classpath 'com.google.gms:google-services:4.3.3'
  • In the android/app/build.gradle – apply the following changes:
    • apply plugin: ‘com.google.gms.google-services’ // along side the other apply plugin <…>
    • defaultConfig {
      multiDexEnabled true }
    • include in the dependency section: implementation 'com.android.support:multidex:1.0.3'

Authenticate with Google

  • If you want to use google_sign_in, a must for an Android Application you could do something like:
final GoogleSignInAuthentication googleAuth = await googleUser.authentication;

// Create a new credential
final OAuthCredential credential = GoogleAuthProvider.credential(
  accessToken: googleAuth.accessToken,
  idToken: googleAuth.idToken,
);
// Once signed in, return the UserCredential
return await FirebaseAuth.instance.signInWithCredential(credential);
  • All the other options of acquiring external credentials are described here: https://firebase.flutter.dev/docs/auth/social

Side Tips and Fixes

In the beginning, I forgot to turn on – Sign in with Google in the Firebase Cloud Console. As a result I received an error similar to this one: https://github.com/flutter/flutter/issues/44538. I tried to reproduce it afterwards, but now, it returns the more meaningful message in the exception of “You forgot to turn on [Google Sign In] feature”. Anyway, if you get this, verify all configuration again. Listen and handle errors in:

GoogleSignIn().signIn().onError((error, stackTrace) {...});

If you plan to support null safety, do it at the beginning, so you do not have problems in the code to resolve and handle stuff right the first time. It is activated by bumping up the SDK in the pubspec.yaml:

environment:
  sdk: ">=2.12.0 <3.0.0"

 

You could watch a Video Demonstration of the integration on YouTube. I didn’t trimmed it so you could see all the problems that arise and how I found solution for them. Read more Flutter articles from my blog from the Flutter topic

  • Feature Flags – Enable Functionality from the BackEnd
  • Integrating xAI Grok API with Spring Boot
  • How to Progresively Integrate AI
  • What is an AI Agent
  • Flutter image scaling

Categories

  • Apps (22)
  • ChatGPT (23)
  • Choosing a Framework (38)
  • Flutter (256)
  • Graphical User Interface (14)
  • Marketing (116)
  • Software Development (281)
  • Spring (44)
  • StartUp (22)
  • Uncategorized (14)
  • Uncategorized (4)
  • Vaadin (14)

Tags

Algorithms (9) crypto (29) flutterdev (39) General (86) Java (7) QR & Bar Codes (3) Software Dev Choices (33) Spring Boot (1) standards (1) Theme (3) User Authentication & Authorization (9) User Experience (10) Utilities (19) WordPress (11)

Product categories

  • All Technologies (84)
    • Flutter Apps (24)
    • GPT (4)
    • Java (38)
    • Native Android (3)
    • PHP (9)
    • Spring (Boot) / Quarkus (35)
    • Utils (15)
    • Vaadin 24+ (27)
    • Vaadin 8 (1)
  • Apps (18)
    • Employees DB (1)
    • Notes (6)
    • Personal Budget (1)
    • Recipes Book (1)
    • Stuff Organizer (1)
    • To-Do (2)
  • PDF Books (3)
  • Source Code Generators (8)

Recent Posts

  • Feature Flags – Enable Functionality from the BackEnd
  • Integrating xAI Grok API with Spring Boot
  • How to Progresively Integrate AI
  • What is an AI Agent
  • Flutter image scaling

Post Categories

  • Apps (22)
  • ChatGPT (23)
  • Choosing a Framework (38)
  • Flutter (256)
  • Graphical User Interface (14)
  • Marketing (116)
  • Software Development (281)
  • Spring (44)
  • StartUp (22)
  • Uncategorized (14)
  • Uncategorized (4)
  • Vaadin (14)