欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

flutter?常見圓角處理示例詳解

 更新時間:2023年03月19日 08:55:08   作者:會煮咖啡的貓  
這篇文章主要介紹了flutter?常見圓角處理示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

flutter 常見圓角處理

圓角處理是 flutter 中不可回避的,頭像、背景、自定義裁切等等。

這篇文摘羅列了常見的幾種圓角處理代碼。

效果

代碼 github.com/ducafecat/f…

步驟

ClipRRect 方式:

這種方式是包裹在圖片上,然后通過裁切的方式進(jìn)行圓角處理,很常見。

如果你要裁切成圓形,Radius = 邊長 / 2

    ClipRRect(
      borderRadius: BorderRadius.circular(10),
      child: Image.asset(
        'assets/desktop.jpg',
        width: 100,
        height: 100,
        fit: BoxFit.cover,
      ),
    );

ClipOval 方式:

直接對一張圖片進(jìn)行圓形裁切,一般用在用戶頭像處理。

    ClipOval(
      child: Image.asset(
        'assets/desktop.jpg',
        width: 100,
        height: 100,
        fit: BoxFit.cover,
      ),
    );

ClipPath 方式:

這種方式用在自定義裁切一張圖片,比如機(jī)票左右兩側(cè)的三角凹陷。

你需要自定義一個 Clip Path。

class MyCustomClipper1 extends CustomClipper<Path> {
  @override
  Path getClip(Size size) {
    var path = Path();
    // 四個圓角,圓角半徑為20
    path.addRRect(RRect.fromLTRBR(
        0, 0, size.width, size.height, const Radius.circular(20)));
    return path;
  }

  @override
  bool shouldReclip(CustomClipper<Path> oldClipper) {
    return false;
  }
}
		ClipPath(
      clipper: MyCustomClipper1(),
      child: Image.asset(
        'assets/desktop.jpg',
        width: 100,
        height: 100,
        fit: BoxFit.cover,
      ),
    );

BoxDecoration 方式:

這種方式用在背景圖片的圓角處理,比如用戶首頁封面圖,廣告輪播圖。

		Container(
      decoration: const BoxDecoration(
        borderRadius: BorderRadius.all(Radius.circular(10)),
        image: DecorationImage(
          image: AssetImage('assets/desktop.jpg'),
          fit: BoxFit.cover,
        ),
      ),
      width: 100,
      height: 100,
    );

小結(jié)

本文羅列了4中常見圓角處理方式,更多關(guān)于flutter 常見圓角處理的資料請關(guān)注腳本之家其它相關(guān)文章!

以上就是flutter 常見圓角處理示例詳解的詳細(xì)內(nèi)容,更多關(guān)于flutter 常見圓角處理的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評論