設(shè)置背景圖片
做移動開始的朋友都知道項目中很多時候要用到用圖片做背景攻询,當然flutter也可以設(shè)置背景圖片。
具體代碼如下:
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),
),
),
),
);
}
}
運行效果如下:
效果圖片