[英]How to pass the gallery image to another Statefull Screen in flutter
Here is my code:这是我的代码:
Future getImage() async {
var image = await ImagePicker.pickImage(source: ImageSource.gallery);
setState(() {
_image = image;
print('Image Path $_image');
});
}
The image
returned from ImagePicker.pickImage(...)
is a File
object that you can pass around to other widgets, just like you would with any other object.从
ImagePicker.pickImage(...)
返回的image
是一个File
对象,您可以将其传递给其他小部件,就像使用任何其他对象一样。 For example, consider this snippet, where NewPage
takes a File
image object as a parameter:例如,考虑这个片段,其中
NewPage
将一个File
图像对象作为参数:
Future<void> navigateOnImage() async {
var image = await ImagePicker.pickImage(source: ImageSource.gallery);
Navigator.of(context)
.push(MaterialPageRoute(builder: (_) => NewPage(image)));
}
Another option may be to convert the File
object to a more handy object for your use case, such as a UInt8List
object, with the File.readAsBytes
method.另一种选择可能是使用
File.readAsBytes
方法将File
对象转换为更方便的对象以适合您的用例,例如UInt8List
对象。 Then you can pass that around just like in the example above.然后你可以像上面的例子一样传递它。
Check out this flutter.dev article for more info on passing data when navigating.查看此 flutter.dev 文章,了解有关在导航时传递数据的更多信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.