官网连接:Flutter
1、组件的使用 :Row Widget布局 横向布列表,里面的子元素都是横着的,水平布局。 Expanded( ) 灵活布局,即可以自适应宽度。 不使用 Expanded( )组件则展示元素本身大小。
2、代码示例:
import 'package:flutter/material.dart'; //主入口方法 void main() => runApp(MyApp()); class MyApp extends StatelessWidget{ @override Widget build(BuildContext context) { return MaterialApp( title: 'Row Widget', home: Scaffold( appBar: AppBar( title: Text('水平方向布局'), ), body: Row( children: <Widget>[ Expanded( child: RaisedButton( onPressed: (){}, color: Colors.red, child: Text('红色按钮'), ), ), Expanded( child: RaisedButton( onPressed: (){}, color: Colors.grey, child: Text('灰色按钮'), ), ), Expanded( child: RaisedButton( onPressed: (){}, color: Colors.blue, child: Text('蓝色按钮'), ), ), ], ), ), ); } }3、效果截图:
