Add Google-login to a Flutter app using Firebase Authentication [ 5 minute tutorial]

Поделиться
HTML-код
  • Опубликовано: 9 сен 2024
  • Learn how to add Google-login to a Flutter app in less than 5 minutes. A fast tutorial with to-the-point instructions.
    Important links:
    A longer version of the video will be available here - [Will be available by tomorrow].
    Learn more about getting the SHA-1 key: developers.goo...
    Copy-Paste items:
    1. Command to get debug SHA-1 (for Windows): keytool -list -v -alias androiddebugkey -keystore %USERPROFILE%\.android\debug.keystore
    2.Add firebase_auth package: flutter pub add firebase_auth
    3.Add google_sign_in package: flutter pub add google_sign_in
    Prerequisites:
    Add Firebase to Flutter: • How to Add Firebase to...

Комментарии • 84

  • @hamzasiddiqui1196
    @hamzasiddiqui1196 Год назад +3

    4:30 I was missing this step.. thanks for highlighting it.

    • @droidmonk4820
      @droidmonk4820  Год назад

      Hi Hamza, thanks for commenting. Stay connected.

  • @dyle9691
    @dyle9691 Месяц назад +1

    I owe it to you king 👑🐐

  • @sulemanali8542
    @sulemanali8542 Год назад +1

    It really helped sir kindly request to you to make more tutorials on firebase plz

    • @droidmonk4820
      @droidmonk4820  Год назад

      Thanks for commenting Suleman. New videos are coming soon. Stay connected.

  • @nanjiboyy7007
    @nanjiboyy7007 Год назад +1

    Amazing video thanks

  • @shuamilabs
    @shuamilabs 7 месяцев назад

    thank you for this tutorial. it help me.

    • @droidmonk4820
      @droidmonk4820  7 месяцев назад

      Glad it helped.
      Stay Connected.

  • @unknown38835
    @unknown38835 3 месяца назад

    Gran video, me sirvió muchísimo

    • @droidmonk4820
      @droidmonk4820  3 месяца назад

      me alegro de escuchar eso
      Mantente conectado

  • @sahadevkunwar9426
    @sahadevkunwar9426 Год назад

    Really helped thanks buddy

  • @DilipKumar-ou2pn
    @DilipKumar-ou2pn Год назад

    really appreciate it thanks a lot

  • @thc8706
    @thc8706 5 месяцев назад +1

    thank you. I do successfully. But you forgot to replace the google-services.json file

    • @droidmonk4820
      @droidmonk4820  5 месяцев назад

      Thanks, I shall check.
      Stay connected.

  • @nguyentantien6262
    @nguyentantien6262 Год назад

    thank you so much

  • @akashkv41
    @akashkv41 2 месяца назад

    Thank you

  • @flutter_oomg-xi5nq
    @flutter_oomg-xi5nq Год назад

    Nice video brother make more

    • @droidmonk4820
      @droidmonk4820  Год назад

      Trying to make more bro. Stay connected.
      Thanks for commenting.

  • @battlegroundsinindia1336
    @battlegroundsinindia1336 Год назад

    well done bro

  • @moshehta2827
    @moshehta2827 9 месяцев назад

    Awsome ❤❤

  • @nomanabdulmalik7904
    @nomanabdulmalik7904 2 года назад +1

    I'm facing this error how I can solve it, kindly reply:
    throw PlatformException(code: errorCode, message: errorMessage as String?, details: errorDetails, stacktrace: errorStacktrace);

    • @droidmonk4820
      @droidmonk4820  2 года назад +1

      Can you share some more information about the error?

    • @nomanabdulmalik7904
      @nomanabdulmalik7904 2 года назад

      @@droidmonk4820
      Here is my code when I call this function on button and pressed button it shows error which was mention in 1st comment.
      signInWithGoogle() async {
      GoogleSignInAccount? googleUser = await GoogleSignIn().signIn();
      GoogleSignInAuthentication? googleAuth = await googleUser?.authentication;
      AuthCredential credential = GoogleAuthProvider.credential(
      accessToken: googleAuth?.accessToken,
      idToken: googleAuth?.idToken,
      );
      UserCredential userCredential =
      await FirebaseAuth.instance.signInWithCredential(credential);
      if (userCredential.user != null) {
      Navigator.of(context)
      .pushReplacement(MaterialPageRoute(builder: (context) => TodoAPP()));
      }
      }

    • @earthplanet1541
      @earthplanet1541 2 года назад

      @@droidmonk4820 When I try to do the code on web I get the same Issue, can you make a video on how to do auth on web and mobile in the same app?

    • @droidmonk4820
      @droidmonk4820  2 года назад +1

      I shall create a video for sure, but for now just try to make sure that you are adding the appropriate SHA key. The issue seems to be related to the SHA-1 key.
      You can find more information on : developers.google.com/android/guides/client-auth
      You can also get the the SHA-1 key using gradle's singing report:
      developers.google.com/android/guides/client-auth#using_gradles_signing_report

  • @roomian
    @roomian Год назад +1

    How would you implement the stay logged in feature in this code? Suppose the user opened the app for the first time and they logged in using the "sign in with google plus" icon and then after selecting desired google account the user goes to the home page. The user then closes the application(doesn't log out) and upon reopening the app again the user should not face the signin or login page again. The user should go straight to the home page of the application and this should keep happening until the user presses a logout button. I implemented this code but the code started acting weird. The sign in pop up kept appearing, the stay logged in feature stopped working only after I had implemented the google auth. I haven't used your code yet as I didn't know how to implement the stay logged in feature in your code. Could you help me with this?

    • @roomian
      @roomian Год назад +1

      So I implemented your code into my app and you have already implemented the stay logged in feature( I don't understand how, I'm new to flutter, I was using instance.user before to detect if there was a current user with logged in credentials). The problem of the app acting weird is still there. The choose an account pop up appears repeatedly only after I logout of the app after signing in while the app is running. If I sign in the app for the first time. Close the app. Restart the app and then log out then the issue doesn't appear.

    • @roomian
      @roomian Год назад

      please help :_)

    • @droidmonk4820
      @droidmonk4820  Год назад +1

      Hi Taimoor , thanks for reaching out. I would love to help you, but from your explanation the problem is not yet clear to me. I would better if you somehow can share the related code.

    • @roomian
      @roomian Год назад +1

      @@droidmonk4820 Thank you so much for the response sir. The issue was solved. Apparently you have to dispose of any timer functions if you want to use any of the social services like google login, facebook login etc. That was the issue. I used your code too it works really well. Thank you so much.

    • @droidmonk4820
      @droidmonk4820  Год назад +1

      Thanks for sharing your solution Taimoor, it will help others. Stay connected.

  • @lufthazka
    @lufthazka Год назад

    everything went well, but why when I log out and then log in again a second time using the same account, the page doesn't move to home instead it stays on the login page. There is no error even displayName has appeared in the console.

    • @droidmonk4820
      @droidmonk4820  Год назад

      Are you checking the authentication status before loading the pages?

    • @lufthazka
      @lufthazka Год назад

      @@droidmonk4820 forget it, turns out I forgot to remove the navigator.pushReplacement after the signout code 😂, and now it's working fine. Thank you sir

  • @liewpeimun5369
    @liewpeimun5369 Год назад

    hi bro, how to remove Black Status Bar Slide to Bottom after tapping the GoogleLoginButton?

    • @droidmonk4820
      @droidmonk4820  Год назад

      Hi, I have found that this issue has been reported. You can find some solutions the thread below. I haven't tried the solutions yet, if you try then let us all know if it worked for you .
      github.com/flutter/flutter/issues/48371

  • @SayedTahsin
    @SayedTahsin Год назад

    Whenever I am selecting my mail its not working. (showing the following error on console and getting back at the same page) error: Expecting binder but got null!
    Can you plz provide me a solution here?

    • @droidmonk4820
      @droidmonk4820  Год назад

      Hi , are you still having the issue. Are you using an emulator?

  • @ciurdea8984
    @ciurdea8984 Месяц назад

    I get this error when i press sign in button, any help?
    ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null, null)

    • @droidmonk4820
      @droidmonk4820  Месяц назад

      Please check once whether you have added the SHA fingerprint to the Firebase project?

  • @JBtronic
    @JBtronic Год назад

    I was facing error on cmd regarding keytool. I set it by setting environment variable. After that, I was facing issue while typing keystore password. I tried 'changeit' or simple enter press but nothing works but then i found solution that was to simply write 'android' when it ask for keystore password.

    • @droidmonk4820
      @droidmonk4820  Год назад +1

      Yah, the default keystore password for debug certificate is "android"

    • @mehakjiwani864
      @mehakjiwani864 9 месяцев назад

      can you please elaborate how did u set enviroment variable

  • @jonyifamily7311
    @jonyifamily7311 8 месяцев назад

    Sorry mster but no thing display when I click on the button of login

    • @droidmonk4820
      @droidmonk4820  8 месяцев назад +1

      Take a look at the console and see if you get any information about an error, if you find then share with me.
      And thanks for reaching out, stay connected.

    • @jonyifamily7311
      @jonyifamily7311 8 месяцев назад

      @@droidmonk4820 the error is google sign in canceled I tried a lot but with out any benefits

  • @maicolr8083
    @maicolr8083 11 месяцев назад

    I LOVE YOU SO MUCH (you salve my @ss), you don't know how much appreciate that

    • @droidmonk4820
      @droidmonk4820  11 месяцев назад +1

      Keep working your @ss off buddy. Stay connected.

  • @user-ss1sz1ks7e
    @user-ss1sz1ks7e 5 месяцев назад

    Thank uyo

  • @learnwithshadyar
    @learnwithshadyar 5 месяцев назад

    Is it same for mac? does not anything else?

    • @droidmonk4820
      @droidmonk4820  5 месяцев назад

      It is the same. Thanks for commenting.
      And sorry for the delay in responding.

    • @learnwithshadyar
      @learnwithshadyar 5 месяцев назад +1

      @@droidmonk4820 NP bro, thank you very much

  • @psjcreations2749
    @psjcreations2749 Год назад

    Getting error by the key code

    • @droidmonk4820
      @droidmonk4820  Год назад

      Hi, thanks for reaching out. Would you share some more information about the error .

  • @robertciobanu622
    @robertciobanu622 Год назад

    hi, could you help me?

  • @kevalpagada3031
    @kevalpagada3031 Год назад

    bro i get error

    • @droidmonk4820
      @droidmonk4820  Год назад

      Can you share the exact error that you are getting?

  • @hemangaborah8526
    @hemangaborah8526 5 месяцев назад

    Arey bapu! Okhomiya neki?

    • @droidmonk4820
      @droidmonk4820  5 месяцев назад

      হয় বন্ধু, ভাল লাগিল লগ পাই 🤗, Stay connected.

  • @oumaimasouid5229
    @oumaimasouid5229 Год назад

    Exception has occurred. PlatformException (PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 12500: , null, null)) how solve it plz

    • @droidmonk4820
      @droidmonk4820  Год назад

      Hi thanks for reaching out.
      Have you added a support email in your firebase project settings?

  • @GumBoomm
    @GumBoomm Год назад

    keytool error: java.lang.Exception: Keystore file does not exist: %USERPROFILE%.android\debug.keystore
    java.lang.Exception: Keystore file does not exist: %USERPROFILE%.android\debug.keystore
    at java.base/sun.security.tools.keytool.Main.doCommands(Main.java:923)
    at java.base/sun.security.tools.keytool.Main.run(Main.java:423)
    at java.base/sun.security.tools.keytool.Main.main(Main.java:416)

    • @droidmonk4820
      @droidmonk4820  Год назад

      Which operating system are you using?
      And thanks for reaching out GUM.

    • @abemelekermias7592
      @abemelekermias7592 9 месяцев назад

      i am facing the same problem and i am using windows
      @@droidmonk4820

  • @abhishekbhujel4158
    @abhishekbhujel4158 4 месяца назад

    Hi Iam gettting this error Google sign-in failed: com.google.android.gms.common.api.ApiException: 10:

    • @droidmonk4820
      @droidmonk4820  4 месяца назад

      This happens when you add a wrong SHA1 key, you have to get the SHA1 for your system.

    • @abhishekbhujel4158
      @abhishekbhujel4158 4 месяца назад

      ​@@droidmonk4820 i generated new sha1 and added but still getting same error

    • @droidmonk4820
      @droidmonk4820  4 месяца назад

      @@abhishekbhujel4158 verify whether you have create the SHA1 for the correct build debug/release

    • @abhishekbhujel4158
      @abhishekbhujel4158 4 месяца назад

      @@droidmonk4820 hi I solved the problem and used your code for a successful google sign in.

    • @aghashabih2299
      @aghashabih2299 4 месяца назад

      @@droidmonk4820 I have done the same SHA 1 and 256 both added using keytool -list -v \
      -alias androiddebugkey -keystore ~/.android/debug.keystore from mac but still same issue on ANDROID

  • @soufianch8481
    @soufianch8481 Год назад

    i try your methode but result ?? plz help me
    C:\>keytool -list -v -alias androiddebugkey -keystore %USERPROFILE%.android\debug.keystore
    'keytool' n’est pas reconnu en tant que commande interne
    ou externe, un programme exécutable ou un fichier de commandes.

    • @droidmonk4820
      @droidmonk4820  Год назад

      "'keytool' is not recognized as an internal command
      or external, an executable program or a batch file."
      --you are getting this as keytool is not added to the environment variable of your system.
      You have to add the path of the directory containing the keytool executable to your %PATH% environment variable.

    • @soufianch8481
      @soufianch8481 Год назад

      @@droidmonk4820 thanks for replay but i don't exist any solutions

    • @droidmonk4820
      @droidmonk4820  Год назад

      @@soufianch8481 check the solution in the link below
      stackoverflow.com/a/6211931