大家好,我有问题再次来到这里。因此,我在我的应用程序中,用户填写了一个表格,然后他必须拍摄一张照片,此照片使用gallery_saver保存在手机中,并且工作正常,但是我必须在我的应用程序中添加用户拍摄的照片的预览,然后我尝试使用一个具有默认图像的FlatButton,单击此按钮将打开相机,在用户制作照片后出现问题,现在我想问的是,在用户拍照后,FlatButton图像将更新为用户拍摄的图片(这是一个网站 具有我要制作的内容,抱歉,该网站不是英语,当您打开网站时,在“ FILTRE”选项卡旁边有一个名为“ SEMNALEAZA PROBLEMA”的选项卡,单击此选项卡,然后您将有3个按钮我想做这样的事情,当用户单击该图标时,它将拍照,然后该图标将在用户拍摄的照片中更新。
在Java中非常简单,因为我们有iD,但是在颤动中我没有注意到类似的东西
这是我拍照的方式:
void _takePhoto() async {
ImagePicker.pickImage(source: ImageSource.camera).then((File image) {
if (image != null && image.path != null) {
setState(() {
recordedImage = image;
attachments.add(FileAttachment(recordedImage));
});
GallerySaver.saveImage(image.path).then((bool success) {
setState(() {});
});
}
});
}
我希望在单击带圆圈的按钮之后,用户将使用上面的代码拍摄图片,并且在用户拍摄图片后,按钮中的默认图像将在用户拍摄的图片中更改。但是我不知道如何告诉我的应用程序从FlatButton更改图像
这是我的按钮代码:
Container(
width: 100,
height: 100,
child: FlatButton(
child: SvgPicture.asset('assets/images/photo.svg'),
onPressed: () {
setState(() {
});
},
),
),
在setState()函数中,将存在函数_takePicture,然后我想在拍照预览中从FlatButton更改图像
如果您需要有关我的代码的更多信息,请随时询问
我使用了来自文档的图像选择器示例,添加了一个按钮,其中包含拍摄后的图片:
import 'package:image_picker/image_picker.dart';
class MyHomePage extends StatefulWidget {
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
File _image;
final picker = ImagePicker();
Future<void> getImage() async {
final pickedFile = await picker.getImage(source: ImageSource.camera);
if(pickedFile != null && pickedFile.path != null) {
setState(() {
_image = File(pickedFile.path);
});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Image Picker Example'),
),
body: Center(
child: _image == null
? FlatButton(child: Text('Pick image.'), onPressed: getImage)
: FlatButton(child: Image.file(_image), onPressed: getImage)
),
);
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句