firebase - 个人资料图像不会改变颤振
问题描述
我有一个用户个人资料,但是一开始我不要求更新那里的图像,他们登录后可以稍后再做,现在在我的编辑屏幕中,当我尝试更改用户图像时,我一直在进行图像输入,我使用 API 将图像上传到 imgur 并获取图像链接(这一直有效),然后我正在尝试更新用户分析我没有任何使用 firebase 的经验,所以我希望它正确发生,但我看不到任何图像持有人的新更新,即使图像是动态加载的,有人可以看看我的代码并指导我,
class editProfile extends StatefulWidget {
static const route = 'editProfile';
@override
_editProfileState createState() => _editProfileState();
}
class _editProfileState extends State<editProfile> {
User? user = FirebaseAuth.instance.currentUser;
String? Imagelink = null;
UserModel loggedInUser = UserModel();
@override
void initState() {
// TODO: implement initState
super.initState();
FirebaseFirestore.instance
.collection("users")
.doc(user!.uid)
.get()
.then((value) {
this.loggedInUser = UserModel.fromMap(value.data());
Imagelink = loggedInUser.Image;
});
}
@override
void didChangeDependencies() {
// TODO: implement didChangeDependencies
super.didChangeDependencies();
FirebaseFirestore.instance
.collection("users")
.doc(user!.uid)
.get()
.then((value) {
this.loggedInUser = UserModel.fromMap(value.data());
});
}
void uploadImage() {
showModalBottomSheet(
context: context,
builder: (BuildContext context) {
return Container(
height: MediaQuery.of(context).size.height * 0.15,
child: Column(
children: [
// IconButton(onPressed: _pickImage, icon: icon)
TextButton.icon(
onPressed: _pickImage,
icon: Icon(Icons.image),
label: Text("Open Gallery")),
TextButton.icon(
onPressed: _pickImageCamera,
icon: Icon(Icons.camera),
label: Text("Take A Picture")),
],
),
);
});
}
@override
Widget build(BuildContext context) {
var name = loggedInUser.firstName;
var secondName = loggedInUser.secondName;
String? college = loggedInUser.CollegeName;
return Scaffold(
body: SafeArea(
child: Center(
child: Column(
children: [
Stack(
alignment: Alignment.bottomRight,
children: [
if (loggedInUser.Image == null)
Container(
width: MediaQuery.of(context).size.height * 0.20,
height: MediaQuery.of(context).size.height * 0.2,
decoration: const BoxDecoration(
shape: BoxShape.circle,
color: Colors.lightBlue,
image: DecorationImage(
fit: BoxFit.cover,
image: NetworkImage(
"http://simpleicon.com/wp-content/uploads/user1.png"))),
)
else
Container(
width: MediaQuery.of(context).size.height * 0.20,
height: MediaQuery.of(context).size.height * 0.2,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Colors.lightBlue,
image: DecorationImage(
fit: BoxFit.cover,
image: NetworkImage(Imagelink!))),
),
ClipOval(
child: Container(
padding: EdgeInsets.all(4),
// width: MediaQuery.of(context).size.width * 0.13,
// height: MediaQuery.of(context).size.width * 0.13,
color: Colors.white,
child: ClipOval(
child: Container(
width: MediaQuery.of(context).size.width * 0.11,
color: Colors.lightBlue,
child: IconButton(
onPressed: uploadImage,
icon: Icon(Icons.edit, color: Colors.white)),
)),
),
)
],
),
],
),
),
),
);
}
Future<void> _pickImageCamera() async {
try {
final newimage =
await ImagePicker().pickImage(source: ImageSource.camera);
if (newimage == null) {
print("object");
return;
}
final tempImage = File(newimage.path);
// final PermaImage = await saveImagePermanently(image.path);
print(newimage.path);
var link = await API_Manager().postImage(newimage.path);
UserModel userModel = UserModel();
setState(() async {
userModel.Image = link;
FirebaseFirestore firebaseFirestore = FirebaseFirestore.instance;
print(userModel);
await firebaseFirestore
.collection("users")
.doc(user!.uid)
.set(userModel.toMap());
Fluttertoast.showToast(msg: "Account created successfully :) ");
});
// var link = await API_Manager().postImage(newimage.path);
// setState(() {
// ImageLink.add(link);
// });
} on PlatformException catch (e) {
print(e);
}
}
Future<void> _pickImage() async {
try {
final newimage =
await ImagePicker().pickImage(source: ImageSource.gallery);
if (newimage == null) {
print("object");
return;
}
final tempImage = File(newimage.path);
// final PermaImage = await saveImagePermanently(image.path);
var link = await API_Manager().postImage(newimage.path);
UserModel userModel = UserModel();
userModel.Image = link;
FirebaseFirestore firebaseFirestore = FirebaseFirestore.instance;
print(userModel.Image);
await firebaseFirestore
.collection("users")
.doc(user!.uid)
.set(userModel.toMap());
Fluttertoast.showToast(msg: "Account created successfully :) ");
setState(() {
// image = tempImage;
Imagelink = link;
});
Navigator.pop(context);
} on PlatformException catch (e) {
print(e);
}
}
}
@override
Widget build(BuildContext context) {
// TODO: implement build
throw UnimplementedError();
}
解决方案
推荐阅读
- node.js - 创建一个函数,用于侦听 FrontEnd 中 BackEnd 调用的变化
- sapui5 - 当数组是对象的属性时如何将数组绑定到列表
- flutter - 何时在 Flutter 中使用新的 Screens 而不是 TabBarView
- mailchimp-api-v3.0 - 如何使用 Mailchimp API 取消归档成员?
- flutter - 在不同屏幕上的自定义导航栏中更改所选项目的颜色
- python - Tkinter Canvas.itemconfigure 没有正确使用?
- c - 为什么这个简单的 C 程序没有显示任何输出?
- spring - 当后端使用 webflux 或简单的 rest 控制器时,web 浏览器有什么不同吗?
- python - 在 Chatterbot 中使用 Ubuntu 数据集时出现 RuntimeError
- java - JasperReport 在 WildFly 中找不到符号 JREvaluator,无需服务器即可工作