Skip to content

Instantly share code, notes, and snippets.

@ryanlid
Created Feb 16, 2020
Embed
What would you like to do?
BoxDecoration装饰盒子-背景图片
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
title: "BoxDecoration装饰盒子-背景图片",
home: LayoutDemo(),
));
}
class LayoutDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("BoxDecoration装饰盒子-背景图片"),
),
body: Center(
child: Container(
width: 300.0,
height: 300.0,
// 装饰器
decoration: BoxDecoration(
// 背景色
color: Colors.grey,
// 图片装饰器
image: DecorationImage(
// 添加 Image 属性
// image: ExactAssetImage('images/1.png'),
image:
NetworkImage("https://static.lidong.me/upload/c7QdErvcb.png"),
fit: BoxFit.cover,
),
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment