Mo711
Mo711

Reputation: 639

Convert a String to a parameter type File Flutter

I am trying to use an image from the photo library of a users phone. It then should be displayed in this container:

child: Container(
     decoration: BoxDecoration(

        borderRadius: BorderRadius.circular(12.0)
        ),
     child:  CircleAvatar(
     backgroundImage: Image.file(path).image,
     radius: 100.0,

  )),

The variable 'path' is a String and contains the path to the image. The error I get tells me that: The argument type 'String' can't be assigned to the parameter type 'File'.

Upvotes: 1

Views: 11284

Answers (1)

farouk osama
farouk osama

Reputation: 2529

Try this:

Container(
     decoration: BoxDecoration(
         image: DecorationImage(
              image: FileImage(File(path))
         )
    )
)

or fix this code from Image.file(path).image to Image.file(File(path)).image

Upvotes: 9

Related Questions