Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- new ListTile(
- title: new Text("Log In"),
- leading: new Icon(Icons.account_box),
- onTap: () => _signIn()
- .then((FirebaseUser user) => print(user))
- .catchError((e) => print(e)),
- subtitle: StreamBuilder(
- stream: FirebaseAuth.instance.onAuthStateChanged,
- builder: (BuildContext context,
- AsyncSnapshot<FirebaseUser> snapshot) {
- if (snapshot.connectionState == ConnectionState.waiting) {
- username = 'loading';
- return Text(username);
- } else if (!snapshot.hasData) {
- username = 'you are not logged in';
- return Text(username);
- } else {
- username = snapshot.data.displayName;
- return Text(username);
- }
- },
- ),
- ),
- new ListTile(
- title: new Text("Log Out"),
- leading: new Icon(Icons.account_circle),
- onTap: () => _signOut(),
- ),
- //this is the sign in code
- Future<FirebaseUser> _signIn() async {
- GoogleSignInAccount googleSignInAccount = await googleSignIn.signIn();
- GoogleSignInAuthentication gSA = await googleSignInAccount.authentication;
- FirebaseUser user = await _auth.signInWithGoogle(
- idToken: gSA.idToken, accessToken: gSA.accessToken);
- print("User Name : ${user.displayName}");
- return user;
- }
- //this is the sign out code
- void _signOut() {
- googleSignIn.signOut();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement