Skip to content

Commit

Permalink
Fix User Profile Page error
Browse files Browse the repository at this point in the history
- Fix null text in name field due to asynchronous update
- Read user-info related fields directly/synchronously from FirebaseAuth.instance
  • Loading branch information
rayjasson98 committed Jan 6, 2021
1 parent 1a0f5e5 commit a27eeb6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
8 changes: 5 additions & 3 deletions lib/data/user/repositories/user_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ class UserRepository {
}

User _currentUser;
static String _uid;
String _uid;
DocumentReference _userDoc;

User get currentUser => _currentUser;
static String get uid => _uid;
User get currentUser => FirebaseAuth.instance.currentUser;
String get uid => FirebaseAuth.instance.currentUser.uid;
String get email => FirebaseAuth.instance.currentUser.email;
String get displayName => FirebaseAuth.instance.currentUser.displayName;

Future<void> saveToken(String token) async {
await _userDoc.update({
Expand Down
10 changes: 8 additions & 2 deletions lib/ui/profile/user_info_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,18 @@ class UserInfoField extends StatelessWidget {
Text _buildFieldValue(BuildContext context, String field) {
if (field == 'displayName') {
return Text(
context.select((UserRepository u) => u.currentUser.displayName),
RepositoryProvider.of<UserRepository>(
context,
listen: false,
).displayName,
style: AppTheme.headline6,
);
} else {
return Text(
context.select((UserRepository u) => u.currentUser.email),
RepositoryProvider.of<UserRepository>(
context,
listen: false,
).email,
style: AppTheme.headline6,
);
}
Expand Down

0 comments on commit a27eeb6

Please sign in to comment.