Skip to content

Commit 98b7aed

Browse files
committed
fixed mdanics#45 - feed now loads after username selection
1 parent fa466b3 commit 98b7aed

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

lib/edit_profile_page.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'dart:async';
33
import 'package:cloud_firestore/cloud_firestore.dart';
44
import 'main.dart'; //for currentuser & google signin instance
55
import 'models/user.dart';
6+
import 'package:shared_preferences/shared_preferences.dart';
67

78
class EditProfilePage extends StatelessWidget {
89
TextEditingController nameController = new TextEditingController();
@@ -123,6 +124,11 @@ class EditProfilePage extends StatelessWidget {
123124
await auth.signOut();
124125
await googleSignIn.signOut();
125126

127+
SharedPreferences prefs = await SharedPreferences.getInstance();
128+
await prefs.clear();
129+
130+
currentUserModel = null;
131+
126132
Navigator.pop(context);
127133
}
128134
}

lib/main.dart

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ Future<Null> _ensureLoggedIn(BuildContext context) async {
3333
user = await googleSignIn.signInSilently();
3434
}
3535
if (user == null) {
36-
await googleSignIn.signIn().then((_) {
37-
tryCreateUserRecord(context);
38-
});
36+
await googleSignIn.signIn();
37+
await tryCreateUserRecord(context);
3938
}
4039

4140
if (await auth.currentUser() == null) {
@@ -58,9 +57,8 @@ Future<Null> _silentLogin(BuildContext context) async {
5857
GoogleSignInAccount user = googleSignIn.currentUser;
5958

6059
if (user == null) {
61-
user = await googleSignIn.signInSilently().then((_) {
62-
tryCreateUserRecord(context);
63-
});
60+
user = await googleSignIn.signInSilently();
61+
await tryCreateUserRecord(context);
6462
}
6563

6664
if (await auth.currentUser() == null && user != null) {
@@ -105,7 +103,7 @@ Future<Null> _setUpNotifications() async {
105103
}
106104
}
107105

108-
tryCreateUserRecord(BuildContext context) async {
106+
Future<void> tryCreateUserRecord(BuildContext context) async {
109107
GoogleSignInAccount user = googleSignIn.currentUser;
110108
if (user == null) {
111109
return null;
@@ -116,7 +114,6 @@ tryCreateUserRecord(BuildContext context) async {
116114

117115
String userName = await Navigator.push(
118116
context,
119-
// We'll create the SelectionScreen in the next step!
120117
new MaterialPageRoute(
121118
builder: (context) => new Center(
122119
child: new Scaffold(
@@ -154,6 +151,7 @@ tryCreateUserRecord(BuildContext context) async {
154151
}
155152

156153
currentUserModel = new User.fromDocument(userRecord);
154+
return null;
157155
}
158156

159157
class Fluttergram extends StatelessWidget {
@@ -233,7 +231,7 @@ class _HomePageState extends State<HomePage> {
233231
setUpNotifications();
234232
}
235233

236-
return googleSignIn.currentUser == null
234+
return (googleSignIn.currentUser == null || currentUserModel == null)
237235
? buildLoginPage()
238236
: new Scaffold(
239237
body: new PageView(

0 commit comments

Comments
 (0)