diff --git a/lib/edit_profile_page.dart b/lib/edit_profile_page.dart index b3b8995..1a95dd1 100644 --- a/lib/edit_profile_page.dart +++ b/lib/edit_profile_page.dart @@ -3,6 +3,7 @@ import 'dart:async'; import 'package:cloud_firestore/cloud_firestore.dart'; import 'main.dart'; //for currentuser & google signin instance import 'models/user.dart'; +import 'package:shared_preferences/shared_preferences.dart'; class EditProfilePage extends StatelessWidget { TextEditingController nameController = new TextEditingController(); @@ -123,6 +124,11 @@ class EditProfilePage extends StatelessWidget { await auth.signOut(); await googleSignIn.signOut(); + SharedPreferences prefs = await SharedPreferences.getInstance(); + await prefs.clear(); + + currentUserModel = null; + Navigator.pop(context); } } diff --git a/lib/main.dart b/lib/main.dart index 88a93c9..6bc0cb0 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -33,9 +33,8 @@ Future _ensureLoggedIn(BuildContext context) async { user = await googleSignIn.signInSilently(); } if (user == null) { - await googleSignIn.signIn().then((_) { - tryCreateUserRecord(context); - }); + await googleSignIn.signIn(); + await tryCreateUserRecord(context); } if (await auth.currentUser() == null) { @@ -58,9 +57,8 @@ Future _silentLogin(BuildContext context) async { GoogleSignInAccount user = googleSignIn.currentUser; if (user == null) { - user = await googleSignIn.signInSilently().then((_) { - tryCreateUserRecord(context); - }); + user = await googleSignIn.signInSilently(); + await tryCreateUserRecord(context); } if (await auth.currentUser() == null && user != null) { @@ -105,7 +103,7 @@ Future _setUpNotifications() async { } } -tryCreateUserRecord(BuildContext context) async { +Future tryCreateUserRecord(BuildContext context) async { GoogleSignInAccount user = googleSignIn.currentUser; if (user == null) { return null; @@ -116,7 +114,6 @@ tryCreateUserRecord(BuildContext context) async { String userName = await Navigator.push( context, - // We'll create the SelectionScreen in the next step! new MaterialPageRoute( builder: (context) => new Center( child: new Scaffold( @@ -154,6 +151,7 @@ tryCreateUserRecord(BuildContext context) async { } currentUserModel = new User.fromDocument(userRecord); + return null; } class Fluttergram extends StatelessWidget { @@ -233,7 +231,7 @@ class _HomePageState extends State { setUpNotifications(); } - return googleSignIn.currentUser == null + return (googleSignIn.currentUser == null || currentUserModel == null) ? buildLoginPage() : new Scaffold( body: new PageView(