'How get the first letter of displayName of a user during google sign in by using flutter and firestore?
And How capitalize the displayName first element?
How I get the capital first letter of displayName of user, who just registered on my app and store the first letter in firestore.
Here is my code to store the data in firestore.
void updateUserData(FirebaseUser user) async {
DocumentReference ref = _db.collection('users').document(user.uid);
return ref.setData({
'uid': user.uid,
'email': user.email,
'photoURL': user.photoUrl,
'displayName': user.displayName,
'lastSeen': DateTime.now()
}, merge: true);
}
Eg Suppose displayName = richie, here what
I want to store a new key value pair in my document
firstletter = R
Thanks In Advance
Solution 1:[1]
It looks like you are already storing the display name in your Firestore Database. I would recommend to not store the first letter in the database as well because this seems a bit redundant, but do with it as you will. In Dart you can use .toUpperCase()
to turn a string into all Uppercase. give this a try:
String firstLetter = user.displayName.substring(0,1).toUpperCase();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Zachery Misson |