亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

Flutter 基礎布局Widgets之Wrap詳解

概述

Wrap好似Row和Column的结合,在横轴的表现和Row一致,而竖轴的表现和Column一致,比如当’this.direction = Axis.horizontal’时,横轴()的child放置不下时就会在竖轴自动扩展一行。

构造函数

Wrap({
    Key key,
    this.direction = Axis.horizontal,
    this.alignment = WrapAlignment.start,
    this.spacing = 0.0,
    this.runAlignment = WrapAlignment.start,
    this.runSpacing = 0.0,
    this.crossAxisAlignment = WrapCrossAlignment.start,
    this.textDirection,
    this.verticalDirection = VerticalDirection.down,
    List<Widget> children = const <Widget>[],
  })
  • direction 扩展方式 比如横向堆砌
  • alignment 对齐方式
  • spacing 主轴空隙间距
  • runAlignment run的对齐方式
  • runSpacing run空隙间距
  • crossAxisAlignment 交叉轴对齐方式
  • textDirection 文本对齐方向
  • verticalDirection 确定垂直放置子元素的顺序,以及如何在垂直方向上解释开始和结束,默认down
  • children 需要放置的组件列表

实例代码

//  Wrap

import 'package:flutter/material.dart';

class WrapLearn extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: AppBar(title: Text('Wrap')),
      // 创建换行布局
      body: Wrap(
        // 扩展方式,横向堆砌
        direction: Axis.horizontal,
        // 对齐方式
        alignment: WrapAlignment.start,
        // 主轴空隙间距
        spacing: 0,
        // run的对齐方式
        runAlignment: WrapAlignment.center,
        // run空隙间距
        runSpacing: 10,
        // 交叉轴对齐方式
        crossAxisAlignment: WrapCrossAlignment.end, 
        // 文本对齐方向
        textDirection: TextDirection.ltr,
        // 确定垂直放置子元素的顺序,以及如何在垂直方向上解释开始和结束。 默认down
        verticalDirection: VerticalDirection.down,
        children: <Widget>[
          Container(
              padding: EdgeInsets.symmetric(vertical: 16, horizontal: 8),
              child: Chip(
                label: Container(
                    padding: EdgeInsets.all(2),
                    constraints: BoxConstraints(
                        // maxHeight: 30,
                        // maxWidth: 100,
                        minHeight: 10,
                        minWidth: 10),
                    decoration: BoxDecoration(
                        // color: Colors.blueAccent
                        ),
                    child: Text(
                      'hello',
                      style: TextStyle(color: Colors.blueAccent, fontSize: 30),
                      overflow: TextOverflow.fade,
                    )),
              )),
          Container(
              padding: EdgeInsets.symmetric(vertical: 16, horizontal: 8),
              child: Chip(
                label: Container(
                    padding: EdgeInsets.all(2),
                    constraints: BoxConstraints(
                        // maxHeight: 30,
                        // maxWidth: 100,
                        minHeight: 10,
                        minWidth: 10),
                    decoration: BoxDecoration(
                        // color: Colors.blueAccent
                        ),
                    child: Text(
                      'hello',
                      style: TextStyle(color: Colors.blueAccent, fontSize: 30),
                      overflow: TextOverflow.fade,
                    )),
              )),
          Container(
              padding: EdgeInsets.symmetric(vertical: 16, horizontal: 8),
              child: Chip(
                label: Container(
                    padding: EdgeInsets.all(2),
                    constraints: BoxConstraints(
                        // maxHeight: 30,
                        // maxWidth: 100,
                        minHeight: 10,
                        minWidth: 10),
                    decoration: BoxDecoration(
                        // color: Colors.blueAccent
                        ),
                    child: Text(
                      'hello',
                      style: TextStyle(color: Colors.blueAccent, fontSize: 30),
                      overflow: TextOverflow.fade,
                    )),
              )),
          Container(
              padding: EdgeInsets.symmetric(vertical: 16, horizontal: 8),
              child: Chip(
                label: Container(
                    padding: EdgeInsets.all(2),
                    constraints: BoxConstraints(
                        // maxHeight: 30,
                        // maxWidth: 100,
                        minHeight: 10,
                        minWidth: 10),
                    decoration: BoxDecoration(
                        // color: Colors.blueAccent
                        ),
                    child: Text(
                      'hello',
                      style: TextStyle(color: Colors.blueAccent, fontSize: 30),
                      overflow: TextOverflow.fade,
                    )),
              )),
          Container(
              padding: EdgeInsets.symmetric(vertical: 16, horizontal: 8),
              child: Chip(
                label: Container(
                    padding: EdgeInsets.all(2),
                    constraints: BoxConstraints(
                        // maxHeight: 30,
                        // maxWidth: 100,
                        minHeight: 10,
                        minWidth: 10),
                    decoration: BoxDecoration(
                        // color: Colors.blueAccent
                        ),
                    child: Text(
                      'hello',
                      style: TextStyle(color: Colors.blueAccent, fontSize: 30),
                      overflow: TextOverflow.fade,
                    )),
              )),
        ],
      ),
    );
  }
}

示例图片:
1FA0A151323C2F5BB47039D767F9F02C.png

點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消