如何在从相机或图库中选择图像后将图像从一个屏幕传递到另一个屏幕,并在我导航到第二个屏幕时自动显示在第二个屏幕中。基本上,我想要一个在第二个屏幕中的方法,当我从相机或图库中选择图像并导航到第二个屏幕时,该方法会自动运行。 这是从图库中选择图像并导航到第二个屏幕的代码
Future<void> predictImagePickerGallery(BuildContext context) async {
final navigator = Navigator.of(context);
var image = await ImagePicker.pickImage(source: ImageSource.gallery);
if (image == null) return;
setState(() {
_busy = true;
_image = image;
});
if (image != null) {
print(image.path);
await navigator.push(
MaterialPageRoute(
builder: (context) =>
Test2(
_image
),
),
);
}
Navigator.of(context).pop();
// recognizeImage(image);
}
现在如何在导航时自动在第二个屏幕中显示此图像。