问题描述
我在我的个人资料表单注册中有此代码。它将拍摄两张不同的照片,但在提交表单后,firebase 只为它们使用一个 Url。这是在用户注册时启动的个人资料表单。这提供给 ProfileBloc,用户存储库是调用 firebase 的地方。它适用于一张照片,我可以在需要第一张照片时调用它。 Firebase 可以看到照片和宠物照片,但两者使用相同的网址,因此它只会显示第一张上传的照片。
class ProfileForm extends StatefulWidget {
final UserRepository _userRepository;
ProfileForm({@required UserRepository userRepository,userId})
: assert(userRepository != null),_userRepository = userRepository;
@override
_ProfileFormState createState() => _ProfileFormState();
}
File photo,petPhoto;
@override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
BlocBuilder<ProfileBloc,ProfileState>(
builder: (context,state) {
Container(
width: size.width,child: Stack(
children: <Widget>[
CircleAvatar(
radius: size.width * 0.3,backgroundColor: Colors.transparent,child: photo == null
? GestureDetector(
onTap: () async {
File getPic =
await FilePicker.getFile(
type: FileType.image);
if (getPic != null) {
setState(() {
photo = getPic;
});
}
},child: Image.asset(
'assets/images/addPhoto.png'),)
: GestureDetector(
onTap: () async {
File getPic =
await FilePicker.getFile(
type: FileType.image);
if (getPic != null) {
setState(() {
photo = getPic;
});
}
},child: CircleAvatar(
radius: size.width * 0.3,backgroundImage: FileImage(photo),),Positioned(
top: 50,left: 150.0,child: petPhoto == null
? GestureDetector(
onTap: () async {
File getPetPic =
await FilePicker.getFile(
type: FileType.image);
if (getPetPic != null) {
setState(() {
petPhoto = getPetPic;
});
}
},child: Image.asset(
'assets/images/addPetPhoto.png'),)
: GestureDetector(
onTap: () async {
File getPetPic =
await FilePicker.getFile(
type: FileType.image);
if (getPetPic != null) {
setState(() {
petPhoto = getPetPic;
});
}
},backgroundImage:
FileImage(petPhoto),)
],));}}
Future<User> userInfo(userId) async {
User _user = User();
await _firestore.collection('users').document(userId).get().then((user) {
_user.uid = user.documentID;
_user.photo = user['photoUrl'];
_user.petPhoto = user['petPhotoUrl'];
});
return _user;
}
//profile setup
Future<void> profileSetup(File photo,String userId,File petPhoto) async {
StorageUploadTask storageUploadTask;
storageUploadTask = FirebaseStorage.instance
.ref()
.child('userPhotos')
.child(userId)
.child(userId)
.putFile(photo);
return await storageUploadTask.onComplete.then((ref) async {
await ref.ref.getDownloadURL().then((url) async {
await ref.ref.getDownloadURL().then((urlPet) async {
await _firestore.collection('users').document(userId).setData({
'uid': userId,'photoUrl': url,'petPhotoUrl': urlPet,});
});
});
});
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)