【发布时间】:2021-08-09 02:03:22
【问题描述】:
我在保存从 firebase 实时数据库中检索图片的 URL 时收到此错误
type '_Uri' is not a subtype of type 'String'
我所做的是首先将图像 URL 存储在 firebase 存储中,然后将 URL 保存在我的 firebase 实时数据库中的当前用户信息下,但是当我从 Db 访问个人资料图像 URL 时,它给了我错误上面提到过。
我的屏幕视图如下所示,我想在其中显示用户选择作为当前用户个人资料图像的图像,直到用户更改图像。
我的函数代码是:
FirebaseAuth firebaseAuth = FirebaseAuth.instance;
final ref = FirebaseDatabase.instance.reference();
final fb = FirebaseDatabase.instance;
Future<Uri> getPicture() async {
User cuser = await firebaseAuth.currentUser;
return ref
.child('User_data')
.child(cuser.uid)
.once()
.then((DataSnapshot snap) {
final String profileURL = snap.value['profile_photo'].toString();
var myUri = Uri.parse(profileURL);
print(myUri);
return myUri;
});
}
从数据库中显示和检索图像的代码:
Center(
child: Stack(
alignment: Alignment.center,
children: <Widget>[
FutureBuilder(
future: getPicture(),
builder: (context, snapshot)
{
if (snapshot.hasData)
{
return CircleAvatar(
radius: 50,
backgroundImage: snapshot.data == null
? AssetImage("assets/images/avatar.jpg")
: Image.network(snapshot.data),
);
}
}
),
Positioned(
bottom: 1,
right: 1,
child: IconButton(
icon: Icon(
Icons.add_circle,
color: const Color(0xffd4d411),
size: 30,
),
onPressed: () {
showModalBottomSheet(
context: context,
builder: ((builder) => bottomSheet(context)),
);
},
//color: const Color(0xffd4d411),
),
)
],
),
),
【问题讨论】:
标签: firebase flutter dart firebase-realtime-database firebase-storage