Flutter 容器 Opacity、CircleAvatar、ClipRRect

新建項(xiàng)目-2.png

Opacity 透明度容器

構(gòu)造函數(shù)

const Opacity({
    Key key,
    @required this.opacity,    //設(shè)置透明度 0-1之間 值越大越不透明
    this.alwaysIncludeSemantics = false, 
    Widget child,
  }) : a

列子

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: new Scaffold(
          appBar: new AppBar(title: new Text('Flutter 透明度容器 Opacity')),
          body: Opacity(
            opacity: 0.2, //設(shè)置透明度,0-1之間
            child: Text(
              'Hello Flutter',
              style: TextStyle(color: Colors.purple, fontSize: 50),
            ),
          )
      )
    );
  }
}
image.png

橢圓形

1. 構(gòu)造函數(shù)

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

2. 例子

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

圓形頭像:

image.png

CircleAvatar 圓形頭像

1. 構(gòu)造函數(shù)

const CircleAvatar({
    Key key,
    this.child,  //設(shè)置子widget后,圖片不會(huì)根據(jù)radius的值改變,需要去設(shè)置backgroundimage
    this.backgroundColor, //背景色
    this.backgroundImage, //背景圖片
    this.foregroundColor, //背景顏色
    this.radius,    //半徑
    this.minRadius, 
    this.maxRadius,
  })

2. 例子

body: CircleAvatar(
  radius: 60,
  backgroundImage: NetworkImage(
      "https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=961039031,2726795919&fm=26&gp=0.jpg"
  ),
)
image.png
const ClipRRect({
    Key key,
    this.borderRadius = BorderRadius.zero, //圓角半徑
    this.clipper,                          //裁剪路徑
    this.clipBehavior = Clip.antiAlias,
    Widget child,
  }) 
image.png

ClipRRect 圓角矩形裁剪

1. 構(gòu)造函數(shù)

const ClipRRect({
    Key key,
    this.borderRadius = BorderRadius.zero, //圓角半徑
    this.clipper,                          //裁剪路徑
    this.clipBehavior = Clip.antiAlias,
    Widget child,
  }) 

2. 列子

//圓角無(wú)邊框
body: ClipRRect(
  borderRadius: BorderRadius.circular(20),
  child: Container(
    width: 100,height: 100,
    child: Image.network(
      "https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=961039031,2726795919&fm=26&gp=0.jpg",
    ),
  ),
image.png
 ClipRRect(
  borderRadius: BorderRadius.circular(20),
  child: Container(
    color: Colors.red,
    padding: EdgeInsets.all(5),
    width: 100, height: 100,
    child: ClipRRect(
      borderRadius: BorderRadius.circular(20),
      child: Image.network("https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=961039031,2726795919&fm=26&gp=0.jpg",),
    )
  ),
)
image.png
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容