Created
February 16, 2020 15:09
-
-
Save ryanlid/6cafe86d0d47f7fe4d439cb56b9b7623 to your computer and use it in GitHub Desktop.
BoxDecoration 装饰盒子
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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