flutter 设置背景图片

不念不忘少年蓝@ 2022-12-22 08:44 273阅读 0赞

设置背景图片

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

  1. class BackgroundImgDemo extends StatelessWidget {
  2. const BackgroundImgDemo({Key key}) : super(key: key);
  3. @override
  4. Widget build(BuildContext context) {
  5. return Container(
  6. decoration: BoxDecoration(
  7. image: new DecorationImage(
  8. fit: BoxFit.cover,
  9. image: new NetworkImage(
  10. 'https://randomuser.me/api/portraits/men/43.jpg'),
  11. ),
  12. ),
  13. child: Container(
  14. color: Colors.red.withOpacity(.5),
  15. child: Center(
  16. child: Text(
  17. "我在图片的上面哦~",
  18. style: TextStyle(color: Colors.white, fontSize: 33),
  19. ),
  20. ),
  21. ),
  22. );
  23. }
  24. }

运行效果如下:

b46101b6fe4e7a0147d27077cb0913f2.webp

作者:Victory_886
链接:https://www.jianshu.com/p/300906739488
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

发表评论

表情:
评论列表 (有 0 条评论,273人围观)

还没有评论,来说两句吧...

相关阅读

    相关 背景图片设置属性

    background-size有3个属性: auto:当使用该属性的时候,背景图片将保持100% 的大小显示,不进行任何缩放。超过div的多余部分将被隐藏。当图片过小时,图片