如何使用flutter和firestore在Google登录期间获取用户的displayName的首字母? [英] How get the first letter of displayName of a user during google sign in by using flutter and firestore?

查看:109
本文介绍了如何使用flutter和firestore在Google登录期间获取用户的displayName的首字母?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以及如何大写displayName首个元素?

我如何获取刚刚在我的注册用户的displayName的首字母大写应用程序并将首字母存储在firestore中。

How I get the capital first letter of displayName of user, who just registered on my app and store the first letter in firestore.

这是我的代码,将数据存储在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);

}

例如假设displayName = richie,在这里

Eg Suppose displayName = richie, here what

我想在文档中存储一个新的键值对

I want to store a new key value pair in my document

firstletter = R

firstletter = R

预先感谢

推荐答案

就像您已经将显示名称存储在Firestore数据库中一样。我建议不要将第一个字母也存储在数据库中,因为这似乎有点多余,但请按照需要进行处理。在Dart中,您可以使用 .toUpperCase()将字符串转换为全部大写形式。尝试一下:

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

这篇关于如何使用flutter和firestore在Google登录期间获取用户的displayName的首字母?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆