【问题标题】:How to decorate Image.file如何装饰 Image.file
【发布时间】:2018-10-03 07:20:02
【问题描述】:

我想让一个文件图像模糊并在其中添加半径。

这是我的代码:

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 小部件实现这一点?

【问题讨论】:

    标签: dart flutter


    【解决方案1】:

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

    new DecorationImage(
      image: new FileImage(yourFile),
      fit: BoxFit.cover,
    );
    

    【讨论】:

      【解决方案2】:

      如果有人想为图像使用条件,这可能会起作用:

      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
         ),
      ),
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-02-03
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多