Firebase Google Authentication made easy with new Firebase Update.

Himanshu Ranjan
Flutter Community
Published in
2 min readOct 6, 2020

Hey Guys, Today we are going to talk about the new firebase update from 30th September and how it changed Authentication methods.

Firebase in the most recent upgrade changed the way Authentication was used in apps. We will be talking about Google Sign-in in this article.

  • Packages you will need:
  • Let’s start with the sign-in function first.
  • Now create a auth.dart file for the sign-in and sign-out methods.
  • Now create another auth_listener.dart file that will help you know the authentication state of the user i.e whether the user is signed in or signed out.

Flutter has introduced this new authStateChanges listener which makes it pretty easy to listen to auth changes.

  • Now to login using google ,create a button and call the login function like this, implement this in your login screen.
  • Now let’s get to the final implementation in main.dart file:

According to the new firebase update, it’s a compulsion to initialize main function like this :

void main() async {  
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
runApp(MyApp());
}
  • For listening to auth changes just use a ternary operator to switch between login and dashboard screen like used above.

Don’t forget to follow me on github:

So,That’s it for this article. See you guys in the next one!

https://www.twitter.com/FlutterComm

--

--

Himanshu Ranjan
Flutter Community

Full Stack Flutter Developer | ML | Firebase | Writer.