![]() |
VOOZH | about |
Firebase is a product of Google that helps developers to build, manage, and grow their apps easily. It helps developers build their apps faster and more securely. No programming is required on the Firebase side which makes it easy to use its features more efficiently. Google Sign-in with Firebase in the Flutter Web app can be done by choosing the account through which you wish to sign in.
Create a new Flutter application using the command Prompt. To create a new app, write the below command and run it.
flutter create app_nameTo know more about it refer this article: Creating a Simple Application in Flutter
To add the dependency to the pubspec.yaml file, add firebase_core and firebase_auth as a dependency in the dependencies part of the pubspec.yaml file, as shown below:
Now run the below command in the terminal.
flutter pub getOr
Run the below command in the terminal.
flutter pub add firebase_core firebase_authTo use libraries, import all of them in the respective .dart file,
import 'package:firebase_auth/firebase_auth.dart';
import 'package:firebase_core/firebase_core.dart';Follow this article to know How to Add Firebase to Flutter App?
After creating a Firebase project in the Firebase Console. In Project Overview, go to And.
β Navigate to project_folder/android/app/build.gradle, where you will find the package name in the defaultConfig section as follows:
defaultConfig {
applicationId "com.example.app" // This is your package name
...
}
AndAndroid Enter a android app name -> Click on Register App.
Note: It is essential to add a SHA-1 key. Refer to this article:- How to Generate SHA-1 Key in Flutter?
β As shown in the below image, Download the google-services.json file and place it in the project-folder/android/app location.
β :
android/build.gradle:android/app/build.gradle:β Click on Continue to console.
β In Firebase Console, go to Build ->Authentication -> Sign-in Method and click below on βGet startedβ.
π Imageβ Click on Google.
π Imageβ Enable Google authentication and set a support email and click on βSaveβ.
π ImageCreate the project structure as shown in the image below.
Create a signInWithGoogle method to enable user login with Google using the firebase_auth and google_sign_in packages.
signInWithGoogle.dart:
Add the boilerplate code below in main.dart to initialize the Firebase in the main function and create a basic structure with an MaterialApp.
main.dart:
Display an Elevated to Sign in using your Google accounts.
sign_in_screen.dart:
Display user details after login.
home_screen.dart :
flutter run
Select any android device per your choice. Then Run the application using above command. Click on the βSign In with Googleβ button and choose your account.
Output: