简体   繁体   English

"将图像从一个屏幕传递到另一个屏幕 - Flutter"

[英]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.

相关问题 Flutter 作为 stream 将数据从一个屏幕传递到另一个屏幕 - Flutter passing data from one screen to another as a stream 如何将图像变量从一个屏幕发送回另一个屏幕 - Flutter - How to send back an image variable from one screen to another - Flutter flutter 使用路由在 flutter 中将阵列数据从一个屏幕传递到另一个屏幕 - flutter passing array data from one screen to another in flutter using route 只有 static 成员可以在初始化程序 flutter 中访问,同时将数据从一个屏幕传递到另一个屏幕 - only static members can be accessed in initializers flutter while passing data from one screen to another screen 在Flutter中将数据从一个屏幕传递到另一个屏幕是空的 - Passing data from one screen to other screen in Flutter is null 在 dart 上将相机从一个屏幕传递到另一个屏幕 - Passing a Camera from one screen to another on dart 将数据从一个屏幕发送到另一屏幕抖动 - send data from one screen to another screen flutter Flutter API 从一个屏幕获取和发送数据到另一个屏幕 - Flutter API Fetch and Sending Data from One screen to another screen 如何:将 flutter 屏幕从一个 flutter 应用程序添加到另一个应用程序? - How To: Add flutter screen from one flutter app to another? 如何在FLutter中使用pushNamed将数据从一个屏幕传递到另一个屏幕? - how to pass data from one screen to another screen with pushNamed in FLutter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM