[英]Passing image from one screen to another - Flutter
I'm using image picker to get the image , and once it's uploaded , I'd like to pass and display it on a different screen.我正在使用图像选择器来获取图像,一旦上传,我想传递并在不同的屏幕上显示它。 now I'm getting this error
现在我收到了这个错误
type 'String' is not a subtype of type 'File' “字符串”类型不是“文件”类型的子类型
<\/blockquote>
First screen :第一个屏幕:
![]()
void _openCamera(BuildContext context) async { final pickedFile = await ImagePicker().getImage( source: ImageSource.camera, ); Navigator.of(context) .push(MaterialPageRoute(builder: (_) => second(image: pickedFile))); }<\/code><\/pre>
second screen :第二个屏幕:
![]()
class second extends StatelessWidget { const second({ Key? key, this.image, }) : super(key: key); final image; @override Widget build(BuildContext context) { \/\/ TODO: implement build return Scaffold( body: SingleChildScrollView( child: Container( padding: EdgeInsets.all(16), child: Card(child: Image.file((image!.path))))), bottomNavigationBar: BottomAppBar( color: Colors.white, ), floatingActionButton: const FloatingActionButton(onPressed: null), ); } }<\/code><\/pre>"
Use XFile?<\/code>
使用
XFile?<\/code>
with
pickImage()<\/code> .
与
pickImage()<\/code> 。
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)));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.