我正在尝试从 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/