[英]Passing image from one screen to another screen in flutter
on first screen ill upload image using camera and i have one button going to next screen.在第一个屏幕上,我使用相机上传图像,我有一个按钮可以转到下一个屏幕。 Here when the user clicks the button image should be sent to the second screen.
这里当用户点击按钮图像时应该发送到第二个屏幕。
below is the code- its a container which captures image and below that is a next button.下面是代码——它是一个捕获图像的容器,下面是一个下一步按钮。
Container(
width: 200,
height: 200,
decoration: BoxDecoration(
border: Border.all(width: 1, color: Colors.black),
borderRadius: const BorderRadius.all(
Radius.circular(8),
),
),
child: _image != null
? Image.file(
File(_image.path),
width: 150,
height: 150,
fit: BoxFit.cover,
)
: AddImage(
icon: Icons.add_a_photo,
onClick: () => getImage(ImageSource.camera)),
),
const SizedBox(
height: 100.0,
),
Padding(
padding: const EdgeInsets.only(top: 39, right: 10),
child: Align(
alignment: Alignment.bottomRight,
child: CustomNextButton(context),
),
),
this is the button widget-这是按钮小部件-
Widget CustomNextButton(context) {
return Container(
//alignment: AlignmentDirectional.bottomEnd,
width: 65,
height: 40,
child: ElevatedButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const SecondPage(image: image)),
);
},
style: ElevatedButton.styleFrom(
backgroundColor: const Color.fromARGB(255, 210, 210, 210),
),
child: const Text(
'Next',
style: TextStyle(fontSize: 14, color: Colors.black),
),
),
);
}
second screen code-第二屏代码-
final File image; //////this is to recieve image.//////
below is the code where i want to show the recieved image下面是我想显示收到的图像的代码
Padding(
padding: const EdgeInsets.only(right: 8.0),
child: Container(
width: 150,
height: 200,
child: Image.file(image),
),
),
I have tried passing the image in button but it's not working.我试过在按钮中传递图像,但它不起作用。 Please help, thanks in advance!!!
请帮助,提前致谢!!!
Use XFile?
使用
XFile?
void _openCamera(BuildContext context) async {
final XFile? pickedFile = await ImagePicker().pickImage(
source: ImageSource.camera,
);
if (pickedFile == null) return;
Navigator.of(context)
.push(MaterialPageRoute(builder: (_) => second(image: pickedFile)));
}
In second screen set your image as在第二个屏幕中将您的图像设置为
Image.file(File(image.path)),
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.