简体   繁体   English

在 flutter 中将图像从一个屏幕传递到另一个屏幕

[英]Passing image from one screen to another screen in flutter

on first screen ill upload image using camera and i have one button going to next screen.在第一个屏幕上,我使用相机上传图像,我有一个按钮可以转到下一个屏幕。 Here when the user clicks the button image should be sent to the second screen.这里当用户点击按钮图像时应该发送到第二个屏幕。

below is the code- its a container which captures image and below that is a next button.下面是代码——它是一个捕获图像的容器,下面是一个下一步按钮。

Container(
                        width: 200,
                        height: 200,
                        decoration: BoxDecoration(
                          border: Border.all(width: 1, color: Colors.black),
                          borderRadius: const BorderRadius.all(
                            Radius.circular(8),
                          ),
                        ),
                        child: _image != null
                            ? Image.file(
                                File(_image.path),
                                width: 150,
                                height: 150,
                                fit: BoxFit.cover,
                              )
                            : AddImage(
                                icon: Icons.add_a_photo,
                                onClick: () => getImage(ImageSource.camera)),
                      ),

   const SizedBox(
                        height: 100.0,
                      ),
                      Padding(
                        padding: const EdgeInsets.only(top: 39, right: 10),
                        child: Align(
                          alignment: Alignment.bottomRight,
                          child: CustomNextButton(context),
                        ),
                      ),

this is the button widget-这是按钮小部件-

Widget CustomNextButton(context) {
  return Container(
    //alignment: AlignmentDirectional.bottomEnd,
    width: 65,
    height: 40,

    child: ElevatedButton(
      onPressed: () {
        Navigator.push(
          context,
          MaterialPageRoute(builder: (context) => const SecondPage(image: image)),
        );
      },
      style: ElevatedButton.styleFrom(
        backgroundColor: const Color.fromARGB(255, 210, 210, 210),
      ),
      child: const Text(
        'Next',
        style: TextStyle(fontSize: 14, color: Colors.black),
      ),
    ),
  );
}

second screen code-第二屏代码-

   final File image;  //////this is to recieve image.//////

below is the code where i want to show the recieved image下面是我想显示收到的图像的代码

          Padding(
                        padding: const EdgeInsets.only(right: 8.0),
                        child: Container(
                          width: 150,
                          height: 200,
                          child: Image.file(image),
                        ),
                      ),

I have tried passing the image in button but it's not working.我试过在按钮中传递图像,但它不起作用。 Please help, thanks in advance!!!请帮助,提前致谢!!!

Use XFile?使用XFile?

 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)));
      }

In second screen set your image as在第二个屏幕中将您的图像设置为

Image.file(File(image.path)),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 "将图像从一个屏幕传递到另一个屏幕 - Flutter" - Passing image from one screen to another - Flutter 将 arguments in flutter 从一个屏幕传递到另一个屏幕 - passing arguments in flutter from one screen to another Flutter 作为 stream 将数据从一个屏幕传递到另一个屏幕 - Flutter passing data from one screen to another as a stream Flutter; 传球集<marker> _markers = {} 从一个屏幕到另一个屏幕</marker> - Flutter; Passing Set<Marker> _markers = {} from one screen to another 如何将图像变量从一个屏幕发送回另一个屏幕 - Flutter - How to send back an image variable from one screen to another - Flutter 只有 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 flutter 使用路由在 flutter 中将阵列数据从一个屏幕传递到另一个屏幕 - flutter passing array data from one screen to another in flutter using route 在 dart 上将相机从一个屏幕传递到另一个屏幕 - Passing a Camera from one screen to another on dart 将数据从一个屏幕发送到另一屏幕抖动 - send data from one screen to another screen flutter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM