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.blue,
// 添加边框,颜色为灰色,宽度为4.0
border: Border.all(
color: Colors.grey,
width: 4.0,
),
// 添加边框弧度这样会一个圆角效果
borderRadius: BorderRadius.circular(36.0),
image: DecorationImage(
// 添加背景图标
// image: ExactAssetImage('images/1.png'),
image:
NetworkImage("https://static.lidong.me/upload/c7QdErvcb.png"),
fit: BoxFit.cover,
),
// 边框阴影效果,可添加多个BoxShadow ,是一种组合效果
boxShadow: [
BoxShadow(
color: Colors.grey, // 阴影颜色
blurRadius: 8.0, // 模糊值
spreadRadius: 8.0, // 扩展阴影半径
offset: Offset(-1.0, 1.0), // x,y 方向偏移量
)
],
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment