我正在嘗試在他們的個人資料頁面上顯示用戶影像,但我不知道如何從 firebase 下載影像:(
這就是我保存影像的方式::
await AuthService.firebase().createUser(
email: _email.text,
password: _password.text,
);
final userId = AuthService.firebase().currentUser?.id;
final destination = 'user-profile-image/$userId'; // here is the location
final ref = FirebaseStorage.instance.ref(destination);
await ref.putFile(_photo!);
imageUrl = await ref.getDownloadURL();
_userService.createNewUser(
userId: userId as String,
userImage: imageUrl as String,
userEmail: _email.text,
userFirstName: _userFirstName.text,
// userCellNumber: _userCellphoneNumber.text,
// userAddress: _userAddress.text,
);
當用戶在應用程式中注冊時,我可以從保存影像的 url 中取回它。
這是我如何取回所有資料的代碼::
String? _firstName;
String? _userId;
String? _imageUrl;
File? _photo; // this is where I want to put the file
getAndSetUserData(userId) async {
var userData = await _cloudFunctions.getUserInfo(userId: userId!);
_userId = userId;
_firstName = userData[userFirstNameColumn];
_imageUrl = userData[userImageColumn];
print(_imageUrl);
log(userData[userFirstNameColumn]);
}
所以現在我需要能夠下載我猜的影像?不確定是否誠實
謝謝您的幫助!
uj5u.com熱心網友回復:
你已經有了 imageUrl。無需下載。只需像這樣直接在您的 UI 中顯示它:
CircleAvatar(
radius: radius,
backgroundImage: NetworkImage(imageUrl!)
或使用第三方快取插件(這是推薦的方式),cache_network_image
CachedNetworkImage(
imageUrl: imageUrl,
imageBuilder: (context, imageProvider) => CircleAvatar(
radius: radius,
backgroundImage: NetworkImage(imageUrl!),
),
)
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/526226.html
