Flutter學習:基礎組件(二)

1.Row

行:在水平方向顯示子控件乳乌,但是不能滾動逻炊。
(注意:行的子控件一般包裹在 Expanded或Flexible小部件中,不然慢宗,行溢出時坪蚁,在行末尾有黃黑色警告條紋奔穿。如下圖)


包含在Expanded中
行溢出時

關于Row的構造器:

 Row({
    Key key,
    MainAxisAlignment mainAxisAlignment = MainAxisAlignment.start,
    MainAxisSize mainAxisSize = MainAxisSize.max,
    CrossAxisAlignment crossAxisAlignment = CrossAxisAlignment.center,
    TextDirection textDirection,
    VerticalDirection verticalDirection = VerticalDirection.down,
    TextBaseline textBaseline,
    List<Widget> children = const <Widget>[],
  }) : super(
    children: children,
    key: key,
    direction: Axis.horizontal,
    mainAxisAlignment: mainAxisAlignment,
    mainAxisSize: mainAxisSize,
    crossAxisAlignment: crossAxisAlignment,
    textDirection: textDirection,
    verticalDirection: verticalDirection,
    textBaseline: textBaseline,
  );
}

參數(shù)名 參數(shù)解釋
MainAxisAlignment 主軸方向的對齊方式(對于Row來說,主軸是橫軸)
MainAxisSize 在主軸方向占有空間的值
crossAxisAlignment 在交叉軸的對齊方式
TextDirection 繪制方向迅细,從左向右還是從右向左
VerticalDirection children繪制順序巫橄,從上向下,或者從下向上
TextBaseline 基線茵典,根據(jù)那個基線對齊
children 添加的子控件

2.Column:

構造器:

Column({
    Key key,
    MainAxisAlignment mainAxisAlignment = MainAxisAlignment.start,
    MainAxisSize mainAxisSize = MainAxisSize.max,
    CrossAxisAlignment crossAxisAlignment = CrossAxisAlignment.center,
    TextDirection textDirection,
    VerticalDirection verticalDirection = VerticalDirection.down,
    TextBaseline textBaseline,
    List<Widget> children = const <Widget>[],
  }) : super(
    children: children,
    key: key,
    direction: Axis.vertical,
    mainAxisAlignment: mainAxisAlignment,
    mainAxisSize: mainAxisSize,
    crossAxisAlignment: crossAxisAlignment,
    textDirection: textDirection,
    verticalDirection: verticalDirection,
    textBaseline: textBaseline,
  );
}

和行的參數(shù)一樣湘换,只不過主軸的對齊方式參考不一樣,對于Row主軸為橫軸统阿,而Column為縱軸彩倚。

3.Stack

取代線性布局,Stack允許子 widget 堆疊, 你可以使用 Positioned 來定位他們相對于Stack的上下左右四條邊的位置。Stacks是基于Web開發(fā)中的絕度定位布局模型設計的贮尉。

 Stack({
    Key key,
    this.alignment = AlignmentDirectional.topStart,
    this.textDirection,
    this.fit = StackFit.loose,
    this.overflow = Overflow.clip,
    List<Widget> children = const <Widget>[],
  }) : super(key: key, children: children);

alignment:對齊方式,默認是左上角哥谷。

4.Container

容器組件,可以設置邊距麻献,填充们妥,大小等限制。

Container({
    Key key,
    this.alignment,
    this.padding,
    Color color,
    Decoration decoration,
    this.foregroundDecoration,
    double width,
    double height,
    BoxConstraints constraints,
    this.margin,
    this.transform,
    this.child,
  }) : assert(margin == null || margin.isNonNegative),
       assert(padding == null || padding.isNonNegative),
       assert(decoration == null || decoration.debugAssertIsValid()),
       assert(constraints == null || constraints.debugAssertIsValid()),
       assert(color == null || decoration == null,
         'Cannot provide both a color and a decoration\n'
         'The color argument is just a shorthand for "decoration: new BoxDecoration(color: color)".'
       ),
       decoration = decoration ?? (color != null ? BoxDecoration(color: color) : null),
       constraints =
        (width != null || height != null)
          ? constraints?.tighten(width: width, height: height)
            ?? BoxConstraints.tightFor(width: width, height: height)
          : constraints,
       super(key: key);

參數(shù) 參數(shù)解釋
alignment 對齊方式
padding 內(nèi)邊距值
color 填充顏色
decoration 設置邊框勉吻、背景色监婶、背景圖片、圓角等屬性
foregroundDecoration 前景裝飾
width 容器寬
height 容器高
constraints 對容器進行裝飾
margin 容器外邊距
transform 矩陣變換
child 子控件
class TestContainer extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new Container(
      padding: EdgeInsets.all(30),
//      color: Colors.green,
      alignment: Alignment(0.1, 0.0),
      width: 250,
      height: 500,
      margin: EdgeInsets.all(20),
      transform: Matrix4.rotationZ(-0.1),
      constraints: BoxConstraints.expand(height: 250.0, width: 500.0),
      foregroundDecoration: BoxDecoration(
          image: DecorationImage(
            image: NetworkImage(
                'http://file06.16sucai.com/2016/0829/37c41d6c1e7af2ece2b3936c0aab86da.jpg'),
          )
      ),
      decoration: new BoxDecoration(
          color: Colors.red,
          borderRadius: BorderRadius.circular(10)
      ),
      child: Text(
        "hello world",
        style: TextStyle(
            fontSize: 50
        ),
      ),
    );
  }
}

運行結果如下:


在這里插入圖片描述
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末齿桃,一起剝皮案震驚了整個濱河市惑惶,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌短纵,老刑警劉巖带污,帶你破解...
    沈念sama閱讀 217,657評論 6 505
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異香到,居然都是意外死亡刮刑,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,889評論 3 394
  • 文/潘曉璐 我一進店門养渴,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人泛烙,你說我怎么就攤上這事理卑。” “怎么了蔽氨?”我有些...
    開封第一講書人閱讀 164,057評論 0 354
  • 文/不壞的土叔 我叫張陵藐唠,是天一觀的道長帆疟。 經(jīng)常有香客問我,道長宇立,這世上最難降的妖魔是什么踪宠? 我笑而不...
    開封第一講書人閱讀 58,509評論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮妈嘹,結果婚禮上柳琢,老公的妹妹穿的比我還像新娘。我一直安慰自己润脸,他們只是感情好柬脸,可當我...
    茶點故事閱讀 67,562評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著毙驯,像睡著了一般倒堕。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上爆价,一...
    開封第一講書人閱讀 51,443評論 1 302
  • 那天垦巴,我揣著相機與錄音,去河邊找鬼铭段。 笑死骤宣,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的稠项。 我是一名探鬼主播涯雅,決...
    沈念sama閱讀 40,251評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼展运!你這毒婦竟也來了活逆?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 39,129評論 0 276
  • 序言:老撾萬榮一對情侶失蹤拗胜,失蹤者是張志新(化名)和其女友劉穎蔗候,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體埂软,經(jīng)...
    沈念sama閱讀 45,561評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡锈遥,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,779評論 3 335
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了勘畔。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片所灸。...
    茶點故事閱讀 39,902評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖炫七,靈堂內(nèi)的尸體忽然破棺而出爬立,到底是詐尸還是另有隱情,我是刑警寧澤万哪,帶...
    沈念sama閱讀 35,621評論 5 345
  • 正文 年R本政府宣布侠驯,位于F島的核電站抡秆,受9級特大地震影響,放射性物質發(fā)生泄漏吟策。R本人自食惡果不足惜儒士,卻給世界環(huán)境...
    茶點故事閱讀 41,220評論 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望檩坚。 院中可真熱鬧着撩,春花似錦、人聲如沸效床。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,838評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽剩檀。三九已至憋沿,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間沪猴,已是汗流浹背辐啄。 一陣腳步聲響...
    開封第一講書人閱讀 32,971評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留运嗜,地道東北人壶辜。 一個月前我還...
    沈念sama閱讀 48,025評論 2 370
  • 正文 我出身青樓,卻偏偏與公主長得像担租,于是被迫代替她去往敵國和親砸民。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 44,843評論 2 354

推薦閱讀更多精彩內(nèi)容