代码之家  ›  专栏  ›  技术社区  ›  Yeahia2508

如何装饰image.file

  •  1
  • Yeahia2508  · 技术社区  · 8 年前

    我要使文件图像模糊并在其中添加半径。

    这是我的代码:

    BackdropFilter(
            filter: new ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0),
            child: new Container(
              width: width * 0.55,
              height: height * 0.70,
              decoration: new BoxDecoration(
    
                //this is not accepted becuse Image.file is not ImageProvider
                image: new DecorationImage(
                    image: new Image.file(new File(messageSnapshot.value['file'])),
                    fit: BoxFit.cover
                ),
    
                borderRadius: new BorderRadius.all(new Radius.circular(10.0)),
              ),
              child: Center(child: new CircularProgressIndicator(backgroundColor: Colors.deepPurpleAccent,)),
            ),
          )
    

    如何使用image.file小部件实现这一点?

    2 回复  |  直到 7 年前
        1
  •  5
  •   Rémi Rousselet    8 年前

    而不是 Image.File 小部件使用 FileImage 图像提供者

    new DecorationImage(
      image: new FileImage(yourFile),
      fit: BoxFit.cover,
    );
    
        2
  •  0
  •   key Austin HLYO    7 年前

    另外,如果有人想使用图像的条件,这可以工作:

    decoration: BoxDecoration(
      borderRadius: BorderRadius.circular(50.0),
        color: Colors.grey,
        image: DecorationImage(
        image: _image == null
        ? AssetImage('A_DEFAULT_IMAGE_PATH')
        : FileImage(YOUR_FILE),
        fit: BoxFit.cover
       ),
    ),