FirebaseAuth 的 displayName 和电子邮件在 flutter app中出现错误

时间:2023-12-12 阅读:50 评论:0 作者:yc888

我想在应用程序屏幕上显示来自 FirebaseAuth 的 displayName 和电子邮件,但是当我尝试将它们放入 Text() 小部件中时,出现错误。

The argument type 'String?' can't be assigned to the parameter type 'String'.dartargument_type_not_assignable
User? get currentUser


这是我尝试执行此操作的代码:


 UserAccountsDrawerHeader(
              accountName: Text(auth.currentUser!.displayName),
              accountEmail: Text(auth.currentUser!.email),
            ),


我尝试了一些不同的方法,但没有任何方法可以消除该错误。

我该如何让它发挥作用? 谢谢


以下是解决代码

您收到错误的原因是文本小部件仅接受不能为空的字符串。 但代码中的 displayName 或 email 为空。


尝试下面代码:

accountName: Text(auth.currentUser?.displayName ?? '')
accountEmail: Text(auth.currentUser?.email ?? '')


本文链接: https://a.10zhan.com/post/4307.html 转载请注明出处!