Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display image in circular shape from external storage

Tags:

flutter

I have tried following code snippet:

new Container(
    height: 80.0,
    width: 80.0,
    decoration: new BoxDecoration
    shape: BoxShape.circle,
    border: Border.all(color: const Color(0x33A6A6A6)),
    // image: new Image.asset(_image.)
    ),
    child: new Image.file(_image),
));

But it's not working.

like image 451
Sunil Avatar asked Jul 03 '18 10:07

Sunil


2 Answers

You can try either the BoxDecoration class with a Radius of 50:

new Container(
    height: 80.0,
    width: 80.0,
    decoration: new BoxDecoration(
        color: const Color(0xff7c94b6),
        borderRadius: BorderRadius.all(const Radius.circular(50.0)),
        border: Border.all(color: const Color(0xFF28324E)),
    ),
    child: new Image.file(_image)
),

the CircleAvatar class:

new CircleAvatar(
  backgroundColor: Colors.brown.shade800,
  child: new Image.file(_image),
),

or more specifically your code is missing a ( after BoxDecoration and has to many ).

So with the BoxShape class:

new Container(
  height: 80.0,
  width: 80.0,
  decoration: new BoxDecoration(
    shape: BoxShape.circle,
    border: Border.all(color: const Color(0x33A6A6A6)),
    // image: new Image.asset(_image.)
  ),
  child: new Image.file(_image),
),
like image 167
Bostrot Avatar answered Sep 21 '22 01:09

Bostrot


here you can do like this to set placeholder image and picked image from camera/gallery

GestureDetector(
  onTap: () => onProfileClick(context), // choose image on click of profile
  child: Container(
    width: 150,
    height: 150,
    decoration: BoxDecoration(
        shape: BoxShape.circle,
        image: DecorationImage(
            image: profilePhoto == null  //profilePhoto which is File object
                ? AssetImage(
                "assets/images/profile_placeholder.png")
                : FileImage(profilePhoto), // picked file
            fit: BoxFit.fill)),
  ),
),
like image 45
Priyanka Avatar answered Sep 21 '22 01:09

Priyanka