Flutter 09

Column
Basically column widget works like rows widget but in different direction.

In the column widget, we insert three container with different sizes, texts and colors.

    body: Column(    children: <Widget>[      Container(        padding: EdgeInsets.all(20.0),        color: Colors.cyan,        child: Text('One')      ),      Container(          padding: EdgeInsets.all(30.0),          color: Colors.blueAccent,          child: Text('Two')      ),      Container(          padding: EdgeInsets.all(40.0),          color: Colors.blueGrey,          child: Text('Three')      ),    ],  ),

Result:

Note that widgets in rows is the order from left to right, while widgets in column start from the top.

We can use mainAxisalignment as well. One thing important is in the Column widget, the main axis is now vertical.

A cool thing is we can insert a row in a column and vice versa.

    body: Column(    children: <Widget>[      Row(        children: <Widget>[          Text('Hello'),          Text(', World!')        ],      ),      Container(        padding: EdgeInsets.all(20.0),        color: Colors.cyan,        child: Text('One')      ),      Container(          padding: EdgeInsets.all(30.0),          color: Colors.blueAccent,          child: Text('Two')      ),      Container(          padding: EdgeInsets.all(40.0),          color: Colors.blueGrey,          child: Text('Three')      ),    ],  ),

Result:

As we can see, the first widget is now the row, the last three container went to the center because the row widget is taking up the full width of the body widget.

Flutter Tutorial for Beginners #12 - Columns


关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章