flutter - 如何在 Flutter 的 Row 中自定义对齐组件?
问题描述
我正在构建一个Card
来显示图像和一些文本信息。我希望 RED Container 内容与顶部对齐,而不是像当前一样居中。我正在使用 aRow
来划分Image
和Texts
内容。除此之外,我想改变Texts
图像右侧整个空间的位置,那么我该如何管理呢?
卡片小部件
Widget buildExerciseCard(BuildContext context, int index) {
return Container(
color: Colors.green,
margin: EdgeInsets.fromLTRB(5, 2, 5, 0),
child: Card(
color: Colors.blue,
child: Row(
children: [
Image.asset(
exerciseList[index].imagePath,
width: 75,
height: 75,
fit: BoxFit.contain,
),
Container(
color: Colors.red,
child: Column(
children: [
Text(exerciseList[index].name),
Text(exerciseList[index].bodyPart),
Text(exerciseList[index].muscle)
],
),
),
],
)),
);
}
解决方案
试试这个代码:
Widget buildExerciseCard(BuildContext context, int index) {
return Container(
color: Colors.green,
alignment: Alignment.topLeft,
margin: EdgeInsets.fromLTRB(5, 2, 5, 0),
child: Card(
color: Colors.blue,
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
Image.asset(
exerciseList[index].imagePath,
width: 75,
height: 75,
fit: BoxFit.contain,
),
Container(
color: Colors.red,
child: Column(
children: [
Text(exerciseList[index].name),
Text(exerciseList[index].bodyPart),
Text(exerciseList[index].muscle)
],
),
),
],
)),
);
}
推荐阅读
- javascript - Firebase - 使用 where 条件更新文档
- kubernetes-helm - 在 helm 图表中重用 uuid
- javascript - Apache ECharts - 用折线图范围选择画笔
- powershell - PowerShell - 如何从服务器列表中获取最新的 Windows 更新?数组/每个问题
- javascript - chart.js - 右侧标签的问题
- javascript - python3中的jQuery有问题
- r - 在 R 函数中重新映射因子水平,甚至更容易
- ruby-on-rails - 如何在rspec中模拟方法重试和变量赋值
- apache2 - PURE-FTPd 和 Apache 用户目录 | 如何在 home 中自动创建 public_html 目录
- c++ - 如何从 sfml 中的函数应用纹理