[英]How to send back an image variable from one screen to another - Flutter
I am new to flutter and I am currently working on a project that uses cameras internally.This screen has two image variables that need to receive an image from the camera and store them easily.我是 flutter 的新手,我目前正在做一个内部使用相机的项目。这个屏幕有两个图像变量,需要从相机接收图像并轻松存储它们。 Right now the camera screen is closed like this:
现在相机屏幕是这样关闭的:
onPressed: ()=> Navigator.pop(context,Image.file(File(imagePath)))
How do I change the Image variables from the previous screen?如何从上一个屏幕更改图像变量?
I see you are passing a widget Image.file(File(imagePath))
to result parameter of Navigator.pop
.我看到您正在将小部件
Image.file(File(imagePath))
传递给Navigator.pop
的结果参数。 So in this case, the code where you open the camera screen using Navigator.push
, you can assign the return value of Navigator.push
to some variable because the return type is Future<T>
.因此,在这种情况下,使用
Navigator.push
打开相机屏幕的代码,您可以将Navigator.push
的返回值分配给某个变量,因为返回类型是Future<T>
。
final imgWidget = await Navigator.push<Image>(...)
Flutter has no concept of different screens. Flutter没有不同屏的概念。 Everything is Widgets and you have a Widget tree.
一切都是小部件,你有一个小部件树。 Between straight Provider, Riverpod, Bloc and GetX there are a variety of different state management solutions that allow you to store information over the level of pages.
在 direct Provider、Riverpod、Bloc 和 GetX 之间,有各种不同的 state 管理解决方案,允许您在页面级别上存储信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.