0
点赞
收藏
分享

微信扫一扫

flutter 设置背景图片

Sky飞羽 2021-10-04 阅读 157

设置背景图片

做移动开始的朋友都知道项目中很多时候要用到用图片做背景,当然flutter也可以设置背景图片。
具体代码如下:

class BackgroundImgDemo extends StatelessWidget {
  const BackgroundImgDemo({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        image: new DecorationImage(
          fit: BoxFit.cover,
          image: new NetworkImage(
              'https://randomuser.me/api/portraits/men/43.jpg'),
        ),
      ),
      child: Container(
        color: Colors.red.withOpacity(.5),
        child: Center(
          child: Text(
            "我在图片的上面哦~",
            style: TextStyle(color: Colors.white, fontSize: 33),
          ),
        ),
      ),
    );
  }
}

运行效果如下:


举报

相关推荐

0 条评论