【发布时间】:2020-11-04 21:33:09
【问题描述】:
我正在使用以下代码在 Flutter 应用程序中选择图像,该应用程序已成功运行。 如果我不想上传图片并想删除选择的图片,我应该怎么做?
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,
),
],
),
现在我只是在挑选图片并尝试删除挑选的图片,我的意思是它应该为空,上传图片是在上下文的后期阶段
【问题讨论】:
-
此代码只选择图片而不是上传它。您需要分享更多代码
-
@UlaşKasım 我已经添加了更多代码,现在我只是删除选择的图像而不是上传它,我的意思是使图像值为空
标签: flutter imagepicker flutter-image