我正在使用以下代码在颤振应用程序中选择图像,该应用程序已成功运行。如果我不想上传图片并想删除挑选的图片,我应该怎么做?
Future getImage() async {
print("get image");
PickedFile image = await _picker.getImage(source: ImageSource.gallery);
if (image != null) {
setState(() {
final File file = File(image.path);
avatarImageFile = file;
isLoading1 = true;
});
}
}
显示图像的代码
Stack(
children: <Widget>[
(avatarImageFile == null)
? (photoUrl != ''
? Material(
child: Image(image: AssetImage('assets/user.jpg'),
width: 100,
height: 100,
fit: BoxFit.cover,
),
clipBehavior:Clip.hardEdge ,
borderRadius: BorderRadius.all(Radius.circular(25.0)),
)
: Icon(
Icons.account_circle,
size: 90.0,
color: Colors.grey,
))
: Material(
child: Image.file(
avatarImageFile,
width: 90.0,
height: 90.0,
fit: BoxFit.cover,
),
borderRadius: BorderRadius.all(Radius.circular(25.0)),
clipBehavior: Clip.hardEdge,
),
IconButton(
icon: Icon(
Icons.camera,
color: Colors.orange.withOpacity(0.5),
),
onPressed: getImage,
padding: EdgeInsets.all(30.0),
splashColor: Colors.transparent,
highlightColor: Colors.grey,
iconSize: 30.0,
),
],
),
现在我只是选择图像并尝试删除选择的图像,我的意思是它应该为空,上传图像是在上下文的后期阶段