从外部存储器显示圆形的图像

Sun*_*nil 1 flutter

我试过以下代码片段:

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),
));
Run Code Online (Sandbox Code Playgroud)

但它不起作用.

Bos*_*rot 6

您可以尝试半径为50 的BoxDecoration类:

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)
),
Run Code Online (Sandbox Code Playgroud)

CircleAvatar类:

new CircleAvatar(
  backgroundColor: Colors.brown.shade800,
  child: new Image.file(_image),
),
Run Code Online (Sandbox Code Playgroud)

或者更具体地说,你的代码(在BoxDecoration之后缺少,并且有很多).

所以使用BoxShape类:

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),
),
Run Code Online (Sandbox Code Playgroud)

  • 我有一个包含图像路径的 File 对象。以上解决方案不起作用。 (2认同)
  • 上面的代码片段正在运行.谢谢,博斯特罗特 (2认同)

Pri*_*agb 6

在这里,您可以这样做来设置占位符图像并从相机/图库中选取图像

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)),
  ),
),
Run Code Online (Sandbox Code Playgroud)