DEV Community

Cover image for Flutter - Firebase Google Sign-in Auth + SplashScreen using updated API

Flutter - Firebase Google Sign-in Auth + SplashScreen using updated API

Sumanth on May 29, 2020

0.Introduction Have you ever wanted to implement user authentication in your flutter Application? Well, you've come to the right place.....
Collapse
 
iamnikhilpardeshi profile image
Nikhil Pardeshi

Sir, first time the program is run without error. Bt second time I open this app show error In home screen. Invalid arguments. What to do??

Collapse
 
sai7xp profile image
Sumanth

Hey Nikhil, thank you for noticing and pointing out the error. (fixed error now)
Cause for error : When the user enters home screen second time it fails to retrieve the name,imageUrl some other details because we haven't stored user details globally.
Anyway, I've fixed the issue and updated the article.
If you found this article useful sharing is highly appreciated. Twitter : @movingmelody :)

Collapse
 
iamnikhilpardeshi profile image
Nikhil Pardeshi

Sir how to resolve these error. Becz I'm beginner in Flutter.

Thread Thread
 
sai7xp profile image
Sumanth

I've updated the code in the article or you can find the code in GitHub repo. Go through the code again. Your error will solve.

Thread Thread
 
iamnikhilpardeshi profile image
Nikhil Pardeshi

Ok sir.

Collapse
 
sai7xp profile image
Sumanth

Still, If you find any issues comment the error. And let me know if error is solved

Collapse
 
laersel2 profile image
laersel2

Invalid argument(s)

The relevant error-causing widget was
HomeScreen
lib\screens\authscreen.dart:79
When the exception was thrown, this was the stack

0 _StringBase.+ (dart:core-patch/string_patch.dart:262:57)

1 _HomeScreenState.build

package:firebase_gsignin/screens/homescreen.dart:17

2 StatefulElement.build

package:flutter/…/widgets/framework.dart:4619

3 ComponentElement.performRebuild

package:flutter/…/widgets/framework.dart:4502

4 StatefulElement.performRebuild

Collapse
 
laersel2 profile image
laersel2

Sir kindly help

Collapse
 
sai7xp profile image
Sumanth

Check the updated code and article

Collapse
 
mikulina profile image
Miku

Were you able to find a solution to this? I'm having the same problem right now. :/

Collapse
 
sai7xp profile image
Sumanth

Actually, that was because the null value is passed to the homescreen from the splashscreen(username). Fixed βœ…βœ… the error now. You can update the code as i updated the article.
Or else simply store the user details in localstorage using the SharedPreferences. It enables you to access the details even in offline mode.
I have commited the new changes to github. If you stuck anywhere look over github repo.

Collapse
 
iamnikhilpardeshi profile image
Nikhil Pardeshi

Hello Sir, last time the program is run Perfectly. Bt now in AuthScreen
=> Error in following lines
1) final AuthResult authResult = await auth.signInWithCredential(credential);
2) final FirebaseUser currentUser = await auth.currentUser();
assert(firebaseUser.uid == currentUser.uid);
return firebaseUser;

& in Splash Screen has returned error.
=> Error in following lines
1) FirebaseAuth.instance.currentUser().then((currentUser) {
if (currentUser == null) {
Timer(Duration(seconds: 2),
() => Navigator.pushReplacementNamed(context, "/auth"));
} else {
Timer(
Duration(seconds: 2),
() => Navigator.of(context).pushAndRemoveUntil(
MaterialPageRoute(
builder: (context) =>
HomeScreen(username: currentUser.displayName)),
(Route route) => false),
);
}
});
What to do, please help me to find these issue??

Collapse
 
feisalfahmi profile image
Feisal Fahmi • Edited

Sir, how to call username, imageUrl and Email in another page ?
I have a problem when i close my app ,then error

Collapse
 
sai7xp profile image
Sumanth

Store the user details locally in your phone using SharedPreferences when user signup. Then simply retrieve the user details in the page you want to use them. Additionally it enables offline access πŸ¦Έβ€β™€οΈ