1

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

Ravindra S. Patil
  • 11,757
  • 3
  • 13
  • 40
Ashwani Kumar
  • 234
  • 5
  • 17
  • What part of this are you stuck on? Seems to me you don't even really need to do anything with Firestore here, since the name of the user is provided by Firebase Authentication, and you should be able to get the FirebaseUser object of the logged in user at any time. – Doug Stevenson Feb 25 '19 at 19:12
  • I want to store the first letter of user's name – Ashwani Kumar Feb 25 '19 at 19:17
  • So it seems like you are just stuck on getting the first letter of `user.displayName`? – Doug Stevenson Feb 25 '19 at 19:23
  • Yes, in capitilization – Ashwani Kumar Feb 25 '19 at 19:29
  • 1
    The documentation for Dart strings is probably where you want to start. https://api.dartlang.org/stable/1.10.1/dart-core/String-class.html – Doug Stevenson Feb 25 '19 at 19:44
  • Does this answer your question? [How to capitalize the first letter of a string in dart?](https://stackoverflow.com/questions/29628989/how-to-capitalize-the-first-letter-of-a-string-in-dart) – Mohammad Nazari Dec 22 '19 at 08:41

1 Answers1

3

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();