flutter 错误: Invalid argument(s): No host specified in URI Instance%20of%2 0'Future%3CString%3E'

标签 flutter firebase url

我正在尝试从 FirebaseFirestore 检索字符串网址。

我的用户界面代码如下

Container(
                                                  height: 65,
                                                  width: 65,
                                                  decoration: BoxDecoration(
                                                      border: Border.all(
                                                          width: 8,
                                                          color: const Color
                                                              .fromARGB(
                                                              255, 3, 54, 95)),
                                                      shape: BoxShape.circle,
                                                      color: Colors.black38),
                                                  child: ClipRRect(
                                                    borderRadius:
                                                        BorderRadius.circular(
                                                            22),
                                                    child: CachedNetworkImage(
                                                      imageUrl:
                                                          model.photoUrl,
                                                      fit: BoxFit.cover,

代码尝试从提供程序文件访问变量,如下所示:

 photoUrl = AuthMethods().getPhotoUrl().toString();

//Auth方法文件

Future<String> getPhotoUrl() async {
    DocumentSnapshot snap = await FirebaseFirestore.instance
        .collection('users')
        .doc(FirebaseAuth.instance.currentUser!.uid)
        .get();

final String photoUrl = (snap.data() as Map<String, dynamic>)['photoUrl'];
return photoUrl;
// return photoUrl;

}

最佳答案

getPhotoUrl() 是一个异步函数,需要等待。它只能工作如果而不是

photoUrl = AuthMethods().getPhotoUrl().toString();

你改为写

photoUrl = await AuthMethods().getPhotoUrl();

尽管这只能像在另一个您可能没有的异步中那样调用

关于 flutter 错误: Invalid argument(s): No host specified in URI Instance%20of%2 0'Future%3CString%3E' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76945505/

相关文章:

firebase - 如何将特定的 ListTile 变量传递给新的页面路由 onTap?

android - Flutter:任务 ':app:compileDebugKotlin' 执行失败

button - 如何在 flutter 中对齐按钮中的文本?

rest - 通过REST API进行Firebase交易

Javascript:有选择地从 URL 中删除哈希(或哈希),以便 URL 保持有效或可用

python - PyQt:setStyleSheet url() 中的特殊字符

flutter - unselectedLabelstyle 在 Flutter 中不起作用

swift - observeSingleEvent 在屏幕上显示从 firebase 获取的数据时会出现延迟。有没有什么办法解决这一问题?

firebase - 创建用户 : { [Error: There are no login transports available for the requested method. 时出错] 代码: 'TRANSPORT_UNAVAILABLE' }

Django-Userena : Overriding profile editing form