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...
4:30 I was missing this step.. thanks for highlighting it.
Hi Hamza, thanks for commenting. Stay connected.
I owe it to you king 👑🐐
Wow...thanks
Stay connected
It really helped sir kindly request to you to make more tutorials on firebase plz
Thanks for commenting Suleman. New videos are coming soon. Stay connected.
Amazing video thanks
Thanks , stay connected.
thank you for this tutorial. it help me.
Glad it helped.
Stay Connected.
Gran video, me sirvió muchísimo
me alegro de escuchar eso
Mantente conectado
Really helped thanks buddy
Glad it helped, STAY CONNECTED
really appreciate it thanks a lot
Glad it helped, stay connected.
thank you. I do successfully. But you forgot to replace the google-services.json file
Thanks, I shall check.
Stay connected.
thank you so much
Glad you liked it, stay connected.
Thank you
Welcome.
Stay connected.
Nice video brother make more
Trying to make more bro. Stay connected.
Thanks for commenting.
well done bro
Thank you , Stay connected.
Awsome ❤❤
Thanks 😊
Stay connected.
I'm facing this error how I can solve it, kindly reply:
throw PlatformException(code: errorCode, message: errorMessage as String?, details: errorDetails, stacktrace: errorStacktrace);
Can you share some more information about the error?
@@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()));
}
}
@@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?
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
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?
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.
please help :_)
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.
@@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.
Thanks for sharing your solution Taimoor, it will help others. Stay connected.
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.
Are you checking the authentication status before loading the pages?
@@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
hi bro, how to remove Black Status Bar Slide to Bottom after tapping the GoogleLoginButton?
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
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?
Hi , are you still having the issue. Are you using an emulator?
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)
Please check once whether you have added the SHA fingerprint to the Firebase project?
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.
Yah, the default keystore password for debug certificate is "android"
can you please elaborate how did u set enviroment variable
Sorry mster but no thing display when I click on the button of login
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.
@@droidmonk4820 the error is google sign in canceled I tried a lot but with out any benefits
I LOVE YOU SO MUCH (you salve my @ss), you don't know how much appreciate that
Keep working your @ss off buddy. Stay connected.
Thank uyo
Welcome, Stay connected.
Is it same for mac? does not anything else?
It is the same. Thanks for commenting.
And sorry for the delay in responding.
@@droidmonk4820 NP bro, thank you very much
Getting error by the key code
Hi, thanks for reaching out. Would you share some more information about the error .
hi, could you help me?
What kind of help do you need?
bro i get error
Can you share the exact error that you are getting?
Arey bapu! Okhomiya neki?
হয় বন্ধু, ভাল লাগিল লগ পাই 🤗, Stay connected.
Exception has occurred. PlatformException (PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 12500: , null, null)) how solve it plz
Hi thanks for reaching out.
Have you added a support email in your firebase project settings?
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)
Which operating system are you using?
And thanks for reaching out GUM.
i am facing the same problem and i am using windows
@@droidmonk4820
Hi Iam gettting this error Google sign-in failed: com.google.android.gms.common.api.ApiException: 10:
This happens when you add a wrong SHA1 key, you have to get the SHA1 for your system.
@@droidmonk4820 i generated new sha1 and added but still getting same error
@@abhishekbhujel4158 verify whether you have create the SHA1 for the correct build debug/release
@@droidmonk4820 hi I solved the problem and used your code for a successful google sign in.
@@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
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.
"'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.
@@droidmonk4820 thanks for replay but i don't exist any solutions
@@soufianch8481 check the solution in the link below
stackoverflow.com/a/6211931