一、简介缓存
二、构造函数markdown
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>[], }) 复制代码
三、例子ide
三个容器横向排放函数
Widget _buildColumn() { return Row( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, textDirection: TextDirection.ltr, textBaseline: TextBaseline.alphabetic, mainAxisSize: MainAxisSize.max, verticalDirection: VerticalDirection.down, children: <Widget>[ Container( height: 50, width: 50, color: Colors.blueAccent, ), Container( height: 50, width: 50, color: Colors.redAccent, ), Container( height: 50, width: 50, color: Colors.greenAccent, ) ], ); } 复制代码
一、简介oop
二、构造函数布局
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>[], }) 复制代码
三、例子ui
三个容器竖向排放,因为设置了up的摆放方式,致使位置是倒过来的this
Widget _buildColumn() { return Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, verticalDirection: VerticalDirection.up, textBaseline: TextBaseline.alphabetic, textDirection: TextDirection.ltr, children: <Widget>[Container( height: 50, width: 50, color: Colors.blueAccent, ), Container( height: 50, width: 50, color: Colors.redAccent, ), Container( height: 50, width: 50, color: Colors.greenAccent, )], ); } 复制代码
一、简介spa
二、构造函数.net
Stack({ Key key, this.alignment = AlignmentDirectional.topStart, this.textDirection, this.fit = StackFit.loose, this.overflow = Overflow.clip, List<Widget> children = const <Widget>[], }) 复制代码
三、例子
将两个容器叠加在一块儿,而且在对齐右下角
Widget _buildColumn() { return Stack( textDirection: TextDirection.ltr, alignment: Alignment.bottomRight, overflow: Overflow.visible, fit: StackFit.loose, children: <Widget>[ Container( width: 100, height: 100, color: Colors.greenAccent, ), Container( height: 50, width: 50, color: Colors.redAccent, ) ], ); } 复制代码
一、简介
二、构造函数
IndexedStack({ Key key, AlignmentGeometry alignment = AlignmentDirectional.topStart, TextDirection textDirection, StackFit sizing = StackFit.loose, this.index = 0, List<Widget> children = const <Widget>[], }) 复制代码
三、例子
经过index控制第二个容器的出现,第一个容器则隐藏
Widget _buildColumn() { return IndexedStack( index: 1, sizing: StackFit.loose, textDirection: TextDirection.ltr, alignment: Alignment.bottomRight, children: <Widget>[ Container( width: 100, height: 100, color: Colors.greenAccent, ), Container( height: 50, width: 50, color: Colors.redAccent, ) ], ); } 复制代码
一、简介
二、构造函数
Flow({ Key key, @required this.delegate, List<Widget> children = const <Widget>[], }) 复制代码
三、例子
在Flow布局中摆放一堆容器,而且大小不一
Widget _buildColumn() { return Flow( delegate: GridFlowDelegate(margin: EdgeInsets.all(10.0)), children: <Widget>[ Container( width: 100, height: 100, color: Colors.greenAccent, ), Container( height: 50, width: 50, color: Colors.redAccent, ), Container( width: 100, height: 100, color: Colors.greenAccent, ), Container( height: 50, width: 50, color: Colors.redAccent, ), Container( width: 100, height: 100, color: Colors.greenAccent, ), Container( height: 50, width: 50, color: Colors.redAccent, ), Container( width: 100, height: 100, color: Colors.greenAccent, ), Container( height: 50, width: 50, color: Colors.redAccent, ), Container( width: 100, height: 100, color: Colors.greenAccent, ) ], ); } 复制代码
在布局管理器中,自定义咱们的摆布方式,以一行中最高的容器做为换行的高度进行横向摆布
class GridFlowDelegate extends FlowDelegate { EdgeInsets margin = EdgeInsets.zero; GridFlowDelegate({this.margin}); @override void paintChildren(FlowPaintingContext context) { var x = margin.left; //绘制子控件的x坐标 var y = margin.top; //绘制子控件的y坐标 var maxHeightIndex = 0; //同一行中最大高度的子控件的索引,用于换行 for (int i = 0; i < context.childCount; i++) { // 当前控件须要的最大宽度 = 控件自己的宽度 + 左右边距 var w = context.getChildSize(i).width + x + margin.right; if (w < context.size.width) { // 若是未超出当前未分配的宽度,则直接平移到对应位置画出来 context.paintChild(i, transform: Matrix4.translationValues(x, y, 0.0)); // 下一次的x坐标 x = w + margin.left; // 在第二个控件开始取同一行的最大高度的控件 if (i >= 1){ var currentHeight = context.getChildSize(i).height + margin.top + margin.bottom; var lastHeight = context.getChildSize(maxHeightIndex).height + margin.top + margin.bottom; if (currentHeight > lastHeight) { // 保留最大高度的索引值 maxHeightIndex = i; } } }else{ // 若是超出当前未分配的宽度,则先归位x坐标恢复默认值,从左边开始从新分配空间 x = margin.left; // y坐标 y += context.getChildSize(maxHeightIndex).height + margin.top + margin.bottom; // 找到坐标后直接平移到对应位置画出来 context.paintChild(i, transform: Matrix4.translationValues(x, y, 0.0)); // 下一次的x坐标须要将它加上本身的宽度,和本身的左右边距 x += context.getChildSize(i).width + margin.left + margin.right; } } } @override bool shouldRepaint(FlowDelegate oldDelegate) { return oldDelegate != this; } } 复制代码
一、简介
二、构造函数
Table({ Key key, this.children = const <TableRow>[], this.columnWidths, this.defaultColumnWidth = const FlexColumnWidth(1.0), this.textDirection, this.border, this.defaultVerticalAlignment = TableCellVerticalAlignment.top, this.textBaseline, }) 复制代码
三、例子
将文字居底对齐的表格
Widget _buildColumn() { return Table( textDirection: TextDirection.ltr, textBaseline: TextBaseline.alphabetic, defaultColumnWidth: FixedColumnWidth(80.0), defaultVerticalAlignment: TableCellVerticalAlignment.bottom, border: TableBorder.all(color: Colors.blueGrey, style: BorderStyle.solid), columnWidths: { 0: FixedColumnWidth(50.0), 1: FixedColumnWidth(100.0), 2: FixedColumnWidth(100.0), }, children: <TableRow>[ TableRow(children: [ Text("序号"), Text("名字"), Text("成绩"), ]), TableRow(children: [ Text("1"), Text("张三"), Text("80"), ]), TableRow(children: [ Text("2"), Text("李四"), Text("88"), ]), TableRow(children: [ Text("3"), Text("王五"), Text("92"), ]) ]); } 复制代码
一、简介
二、构造函数
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>[], }) 复制代码
三、例子
经过Wrap控件建立出竖向的流式布局
Widget _buildColumn() { return Wrap( textDirection: TextDirection.ltr, alignment: WrapAlignment.center, verticalDirection: VerticalDirection.down, crossAxisAlignment: WrapCrossAlignment.center, direction: Axis.horizontal, runAlignment: WrapAlignment.center, runSpacing: 10.0, spacing: 10.0, children: <Widget>[ Chip( label: Text("张三张三张三"), ), Chip( label: Text("李四李四李四"), ), Chip( label: Text("王五王五王五"), ), Chip( label: Text("赵六赵六赵六"), ), Chip( label: Text("钱七"), ), Chip( label: Text("孙八"), ), ], ); } 复制代码
一、简介
二、构造函数
ListBody({ Key key, this.mainAxis = Axis.vertical, this.reverse = false, List<Widget> children = const <Widget>[], }) 复制代码
三、例子
显示3个不一样颜色的容器,因为其父容器是Flex
,会致使ListBody
的侧轴被拉升到最大
Widget _buildColumn() { return Flex( direction: Axis.vertical, children: <Widget>[ ListBody( mainAxis: Axis.vertical, reverse: false, children: <Widget>[ Container( height: 50, width: 50, color: Colors.blueAccent, ), Container( height: 50, width: 50, color: Colors.redAccent, ), Container( height: 50, width: 50, color: Colors.greenAccent, ) ], ), ], ); } 复制代码
一、简介
二、构造函数
ListView({ Key key, Axis scrollDirection = Axis.vertical, bool reverse = false, ScrollController controller, bool primary, ScrollPhysics physics, bool shrinkWrap = false, EdgeInsetsGeometry padding, this.itemExtent, bool addAutomaticKeepAlives = true, bool addRepaintBoundaries = true, double cacheExtent, List<Widget> children = const <Widget>[], }) 复制代码
三、例子
建立三个具备回弹功能的列表控件
Widget _buildColumn() { return ListView( physics: BouncingScrollPhysics(), cacheExtent: 10.0, primary: true, padding: EdgeInsets.all(15.0), reverse: false, scrollDirection: Axis.vertical, children: <Widget>[ Container( height: 300, width: 300, color: Colors.blueAccent, ), Container( height: 300, width: 300, color: Colors.redAccent, ), Container( height: 300, width: 300, color: Colors.greenAccent, ) ], ); } 复制代码
一、简介
二、构造函数
CustomMultiChildLayout({ Key key, @required this.delegate, List<Widget> children = const <Widget>[], }) 复制代码
三、例子
首先建立控件的代理类,包括控件的大小和控件的位置,经过id获取传递过来的子控件,将description
的控件放置在title
下方
class IdLayoutDelegate extends MultiChildLayoutDelegate { IdLayoutDelegate(); @override void performLayout(Size size) { BoxConstraints constraints = BoxConstraints(maxWidth: size.width); // 经过id获取对应的控件大小 Size titleSize = layoutChild("title", constraints); Size descriptionSize = layoutChild("description", constraints); // 摆放id的控件位置 positionChild("title", Offset(0.0, 0.0)); positionChild("description", Offset(0.0, titleSize.height)); } @override bool shouldRelayout(MultiChildLayoutDelegate oldDelegate) { return oldDelegate != null; } } 复制代码
经过id将对应的控件摆布在对应的位置
Widget _buildColumn() { return CustomMultiChildLayout( delegate: IdLayoutDelegate(), children: <Widget>[ LayoutId( id: "title", child: Text("Hensen"), ), LayoutId( id: "description", child: Text("Flutter工程师"), ) ], ); } 复制代码
一、简介
二、构造函数
const LayoutBuilder({ Key key, LayoutWidgetBuilder builder, }) 复制代码
三、例子
经过判断父控件的尺寸大小,若是是大尺寸,就用大图标,若是是小尺寸,就用小图标
Widget _buildColumn() { return LayoutBuilder( builder: (BuildContext context, BoxConstraints constraints) { if (constraints.maxWidth > 200.0) { // 尺寸大的 return FlutterLogo(size: 200); } // 尺寸小的 return FlutterLogo(size: 50); }, ); } 复制代码
![]() Hensen_ |