Flutter基礎

u=653666270,723497068&fm=26&gp=0.jpg

用于記錄我的學習,持續(xù)更新


  • Container

官方解釋:一個擁有繪制、定位、調(diào)整大小的 widget。

image.png

這是比較常用的一個基礎組件,我這里就記錄一下decoration(裝飾盒子)這個屬性,下面是BoxDecoration:

const BoxDecoration({
    this.color,   //背景顏色
    this.image, //背景圖片
    this.border, //邊框
    this.borderRadius, //圓角
    this.boxShadow, //陰影
    this.gradient, //漸變
    this.backgroundBlendMode, //混合模式
    this.shape = BoxShape.rectangle, //形狀
  })

gradient 有兩種漸變 RadialGradientLinearGradient


//可以設置漸變的開始位置跟結束位置
const LinearGradient({
    this.begin = Alignment.centerLeft,
    this.end = Alignment.centerRight,
    @required List<Color> colors,
    List<double> stops,
    this.tileMode = TileMode.clamp,
  })

//由中心擴散 可以設置擴散位置,擴散范圍的大小
const RadialGradient({
    this.center = Alignment.center,
    this.radius = 0.5,
    @required List<Color> colors,
    List<double> stops,
    this.tileMode = TileMode.clamp,
    this.focal,
    this.focalRadius = 0.0,
  })

LinearGradient下圖

image.png

RadialGradient下圖

image.png

這下面是設置的代碼

decoration: BoxDecoration(
          color: Colors.yellow, //背景顏色
          border: Border.all( //邊框
            color: Colors.red,
            width: 3
        ),
         borderRadius: BorderRadius.circular(10), //設置圓角
//            borderRadius: BorderRadius.only(topLeft: Radius.circular(20)), //設置圓角
          boxShadow: [ //陰影
            BoxShadow(
                offset: Offset(10, 10), //陰影偏移
                color: Colors.red, //陰影顏色
                blurRadius: 20, //陰影模糊程度,值越大越模糊 默認0
                spreadRadius: 3 //陰影擴散 正數(shù)就擴散,負數(shù)就縮小,默認是0
            )
          ],
          shape: BoxShape.rectangle, //形狀 可設置矩形,原型,是一個枚舉值
          gradient: RadialGradient(  //徑向漸變
            colors: [
              Colors.blue,
              Colors.cyanAccent
            ],
            radius: 0.5
          ),
//            gradient: LinearGradient( //線性漸變
//                colors: [
//                  Colors.blue,
//                  Colors.cyanAccent
//                ],
//              begin: Alignment.topLeft,
//              end: Alignment.bottomRight
//            )
       ),

  • 排列

Row:在水平方向上排列子widget的列表
Column:在垂直方向上排列子widget的列表。

這個排列不多說,主要想記錄一下主軸交叉軸

class LayoutDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.yellow,
      height: 667,
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[
          IconBadge(Icons.add_comment),
          IconBadge(Icons.add_a_photo),
          IconBadge(Icons.add_call)
        ],
      ),
    );
  }
}
image.png

Row排列中,主軸就是紅色箭頭 從左往右,交叉軸就是綠色箭頭,從上往下
Column排列中,主軸就是綠色箭頭 ,從上往下,交叉軸就是紅色箭頭,從左往右
交叉軸就是與主軸垂直的那條線


  • PageView

分頁滾動的一個視圖

PageView({
    Key key,
    this.scrollDirection = Axis.horizontal, //滾動方向
    this.reverse = false, //是否反向,從最后一個開始
    PageController controller,
    this.physics,
    this.pageSnapping = true, //是否分頁滑動
    this.onPageChanged,  //當前index回調(diào)
    List<Widget> children = const <Widget>[],
    this.dragStartBehavior = DragStartBehavior.start,
  })

PageView.builder({
    Key key,
    this.scrollDirection = Axis.horizontal, //滾動方向
    this.reverse = false, //是否反向,從最后一個開始
    PageController controller, 
    this.physics, 
    this.pageSnapping = true, //是否分頁滑動
    this.onPageChanged, //當前index回調(diào)
    @required IndexedWidgetBuilder itemBuilder, 
    int itemCount,
    this.dragStartBehavior = DragStartBehavior.start,
  })

//    PageController controller, 
PageController({
    this.initialPage = 0, //初始化時候得下標
    this.keepPage = true, //用于保存滾動偏移量的位置
    this.viewportFraction = 1.0, //視圖填充大小
  })

最后編輯于
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

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

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