新建项目-2.png

Opacity 透明度容器


构造函数


  1. const Opacity({
  2. Key key,
  3. @required this.opacity, //设置透明度 0-1之间 值越大越不透明
  4. this.alwaysIncludeSemantics = false,
  5. Widget child,
  6. }) : a

列子

  1. class MyApp extends StatelessWidget {
  2. @override
  3. Widget build(BuildContext context) {
  4. return MaterialApp(
  5. title: 'Flutter Demo',
  6. theme: ThemeData(
  7. primarySwatch: Colors.blue,
  8. ),
  9. home: new Scaffold(
  10. appBar: new AppBar(title: new Text('Flutter 透明度容器 Opacity')),
  11. body: Opacity(
  12. opacity: 0.2, //设置透明度,0-1之间
  13. child: Text(
  14. 'Hello Flutter',
  15. style: TextStyle(color: Colors.purple, fontSize: 50),
  16. ),
  17. )
  18. )
  19. );
  20. }
  21. }

image.png

椭圆形

1. 构造函数

  1. ClipOval({Key key, this.clipper,
  2. this.clipBehavior = Clip.antiAlias,
  3. Widget child}

2. 例子

  1. body: ClipOval(
  2. child: Image.network(
  3. "https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=961039031,2726795919&fm=26&gp=0.jpg"
  4. )
  5. )

圆形头像:

image.png

CircleAvatar 圆形头像

1. 构造函数

  1. const CircleAvatar({
  2. Key key,
  3. this.child, //设置子widget后,图片不会根据radius的值改变,需要去设置backgroundimage
  4. this.backgroundColor, //背景色
  5. this.backgroundImage, //背景图片
  6. this.foregroundColor, //背景颜色
  7. this.radius, //半径
  8. this.minRadius,
  9. this.maxRadius,
  10. })

2. 例子

  1. body: CircleAvatar(
  2. radius: 60,
  3. backgroundImage: NetworkImage(
  4. "https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=961039031,2726795919&fm=26&gp=0.jpg"
  5. ),
  6. )

image.png

  1. body: Container(
  2. margin: EdgeInsets.only(top: 10.0),
  3. width: 80.0,
  4. height: 80.0,
  5. child: ClipRRect(
  6. borderRadius: BorderRadius.circular(5.0),
  7. child: Image.network(
  8. "https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=961039031,2726795919&fm=26&gp=0.jpg",
  9. fit: BoxFit.fill,
  10. ),
  11. ),
  12. ),

image.png

ClipRRect 圆角矩形裁剪

1. 构造函数

  1. const ClipRRect({
  2. Key key,
  3. this.borderRadius = BorderRadius.zero, //圆角半径
  4. this.clipper, //裁剪路径
  5. this.clipBehavior = Clip.antiAlias,
  6. Widget child,
  7. })

2. 列子

  1. //圆角无边框
  2. body: ClipRRect(
  3. borderRadius: BorderRadius.circular(20),
  4. child: Container(
  5. width: 100,height: 100,
  6. child: Image.network(
  7. "https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=961039031,2726795919&fm=26&gp=0.jpg",
  8. ),
  9. ),

image.png

  1. ClipRRect(
  2. borderRadius: BorderRadius.circular(20),
  3. child: Container(
  4. color: Colors.red,
  5. padding: EdgeInsets.all(5),
  6. width: 100, height: 100,
  7. child: ClipRRect(
  8. borderRadius: BorderRadius.circular(20),
  9. child: Image.network("https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=961039031,2726795919&fm=26&gp=0.jpg",),
  10. )
  11. ),
  12. )

image.png