flutter - 行内的容器对齐
问题描述
我想知道如何将 3 个不同的容器排成一行,以便 2 个保持在左侧,1 个保持在右侧。
像这样: http: //prntscr.com/tovlhw。
我所做的方式只适用于这个 AVD,因为它使用像素来定位。
GestureDetector(
onTap: (){
Navigator.push(context, MaterialPageRoute(builder: (context) => Favoritos()));
},
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
padding: EdgeInsets.fromLTRB(10,16,0,16),
color: Colors.white,
child: Icon(Icons.favorite),
),
Container(
padding: EdgeInsets.fromLTRB(5,20,140,20),
color: Colors.white,
child: Text('Favoritos'),
),
Container(
padding: EdgeInsets.fromLTRB(145,16,5,16),
color: Colors.white,
child: Icon(Icons.keyboard_arrow_right),
),
],
),
),
解决方案
这可以使用ListTile
带有小部件的小部件轻松完成Card
(如果您还想要背景颜色):
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Card(
color: Colors.white,
child: ListTile(
title: Text(
'Favourite',
style: TextStyle(color: Colors.black),
),
leading: Icon(Icons.favorite, color: Colors.black),
trailing: Icon(Icons.arrow_right, color: Colors.black),
),
);
}
}
如果您想使用这样的Row
方法Spacer
:还请记住,您可以使用Container
height
属性来使您的行更大。
Container(
color: Colors.white,
child: Row(
children: <Widget>[
Icon(Icons.favorite, color: Colors.black),
SizedBox(
width: 10.0, // give the witdh you want between icon and text
),
Text(
'Favourite',
style: TextStyle(color: Colors.black),
),
Spacer(),
Icon(Icons.arrow_right, color: Colors.black),
],
),
);
推荐阅读
- reactjs - 我可以使用 React.js MapBox GL JS 获取在 MapBox Studio 中创建的 MapBox 图层吗?
- html - 旋转元素的绝对定位到左上角
- math - 几何平移是线性的吗?
- android - 横向布局,无旋转
- python - 使用 curl 登录 phpBB
- swiftui - xcode swift .navigationBarItems 按钮如何在中间对齐并与顶部有一些间距
- popup - Mediawiki:安装弹出窗口扩展
- c# - 如何在棋盘上创建曲线(统一的立方体),角色在哪里可以选择走或不走另一条路?基于骰子的运动
- macos - 我需要一些使用 Mac 终端安装或创建应用程序
- flutter - 为什么我的状态栏图标是黑色的,为什么我不能更改它?(Flutter 2.0 升级后)