Waseem Ahmed
Waseem Ahmed

Reputation: 419

Can't set Image.file to Circular Avatar in flutter

I am trying to use Circular Avatar in my design. however i want to set the image based on a file chosen by the User in their gallery. this image is set to:

File _imageUpload;

This loads properly if i use a container with Image.file

However, CircularAvatar wont accept it as part of the backgroundImage property.

am i meant to convert the file to another file type before assigning it to the Circular Avatar?

Upvotes: 1

Views: 1058

Answers (3)

Waseem Ahmed
Waseem Ahmed

Reputation: 419

I found the issue. In circular avatar you should not use Image.file. instead you should be using FileImage

Upvotes: 1

Claudio Redi
Claudio Redi

Reputation: 68400

Use Image.file for showing a local photo

Image.file(_imageUpload)

Upvotes: 1

Bill_The_Coder
Bill_The_Coder

Reputation: 2510

Try this code

CircleAvatar(
                          radius: 57,
                          backgroundColor: Color(0xff476cfb),
                          child: ClipOval(
                            child: new SizedBox(
                              width: 100.0,
                              height: 100.0,
                              child: (_image != null)
                                  ? Image.file(
                                      _image,
                                      fit: BoxFit.fill,
                                    )
                                  : Image.network(
                                      "Any Url from the internet to display image",
                                      fit: BoxFit.fill,
                                    ),
                            ),
                          ),
                        ),

Upvotes: 1

Related Questions