0

I have an image widget on my page. With the image picker plugin, I want to take an image from my computer and display it in the image picker, but I can't.

If I want, I can show the image in another widget, but I want to show it in the image widget. Where am I making a mistake?

import 'dart:io';
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter_web_image_picker/flutter_web_image_picker.dart';
import 'package:image_picker/image_picker.dart';

class BlackKitchen extends StatefulWidget {
  @override
  _BlackKitchenState createState() => _BlackKitchenState();
}

class _BlackKitchenState extends State<BlackKitchen> {
  
  bool loading = false;
  Image image;
  @override
  Widget build(BuildContext context) {
    final num myHeight = MediaQueryData.fromWindow(window).size.height;
    final num myWidth = MediaQueryData.fromWindow(window).size.width;
    return MaterialApp(
      title: 'My Title',
      theme: ThemeData(
        primarySwatch: Colors.red,
      ),
      home: Scaffold(
        body: Stack(
          overflow: Overflow.visible,
          children: [
            Padding(
              padding: const EdgeInsets.all(8.0),
              child: Center(
                child: loading
                    ? CircularProgressIndicator()
                    : SizedBox(
                        height: 0,
                        width: 0,
                      ),
              ),
            ),
            image!= null
                ? Padding(
                    padding: const EdgeInsets.only(left: 332.0, top: 232.0),
                    child: Visibility(
                      visible: true,
                      child: Image.file(
                        image,
                        width: 839.0,
                        height: 125.0,
                        fit: BoxFit.fill,
                      ),
                    ),
                  )
                : Padding(
                    padding: const EdgeInsets.only(left: 332.0, top: 232.0),
                    child: Image.asset(
                      "images/last.jpg",
                      width: 839.0,
                      height: 125.0,
                      fit: BoxFit.fill,
                    ),
                  ),
            Visibility(
              visible: true,
              child: Image.asset(
                "images/black_kitchen_edited.png",
                fit: BoxFit.fill,
                height: myHeight,
                width: myWidth,
              ),
            ),
          ],
        ),
        floatingActionButton: FloatingActionButton.extended(
          backgroundColor: Colors.white54,
          icon: Icon(Icons.add_a_photo),
          label: Text('Choose Photo'),
          onPressed: () {
            choosePhoto();
          },
        ),
      ),
    );
  }

  choosePhoto() async {
    final _image = await FlutterWebImagePicker.getImage;
    setState(() {
      image = _image;
    });
  }
}

MyError

Error : The argument type 'Image' can't be assigned to the parameter type 'File'.dart(argument_type_not_assignable)

OneMore
  • 89
  • 1
  • 7
  • `_image` is not a file, it is an image. You should load it to widget that takes an image. – fartem Feb 13 '21 at 12:07
  • So how do I convert _image to file? Is this possible – OneMore Feb 13 '21 at 12:50
  • You can use widget that takes images, not files. Read more how to work with images [here](https://api.flutter.dev/flutter/widgets/Image-class.html). – fartem Feb 13 '21 at 13:27

0 Answers0