Flutter 中 Flexible,来来来

// 横向布局(可以看上一篇)
Row(
children: [
Flexible(
// 第一个占用 1/6
flex: 1,
child: getItem(1),
),
Flexible(
// 第 2 个占用 2/6
flex: 2,
child: getItem(2),
),
Flexible(
// 第 3 个占用 3/6
flex: 3,
child: getItem(3),
),
],
)


#### getItem

/// 获取子项目(这里使用了位置参数)
Widget getItem(int index, [double width = 60, double height = 60]) {
return Container(
// 宽高设置 60
width: width,
height: height,
// 设置背景色
color: Colors.orange.shade200,
// 设置间隙
margin: EdgeInsets.all(2),
// 设置子项居中
alignment: Alignment.center,
// 设置子项
child: Text(’$index’),
);
}
}


### 看效果![image.png](https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/4667bd7838fc4cab9e38d6a00153b877~tplv-k3u1fbpfcp-zoom-1.image)  
What? 按照常识来讲这不符合预期啊,刚


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部