flutter - 在颤动中对齐行内的文本
问题描述
在我的fluttr App中,我想在同一行的左侧显示一个文本,并在右侧显示一个按钮。我给出了正确的对齐方式但仍然没有出现,任何人都可以让我知道我在哪里犯了错误,下面是代码
Widget build(BuildContext context) {
return Scaffold(body:SingleChildScrollView(
child: Padding(
padding: const EdgeInsets.symmetric(
vertical: 80.0,
),
child: Container(
child: Row(children: <Widget>[
new Container(
alignment: Alignment.topLeft,
child: Align(
child: Text(
'Filters',
style: const TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
color: Colors.black54),
),
),
),
Container(
alignment: Alignment.topRight,
child: OutlineButton(
child: Text(
'Reset',
style: const TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
color: Colors.black54),
),
onPressed: null,
)),
]),
))));
}
代码输出
如何将过滤器对齐到屏幕的左侧和重置按钮到屏幕的右侧?
谢谢
解决方案
几种获取方式:
1> mainAxisAlignment: MainAxisAlignment.spaceBetween,
用于Row()
或者
2>Spacer()
在您的小部件之间使用小部件。
代码:
Row(
// mainAxisAlignment: MainAxisAlignment.spaceBetween, // first way
children: <Widget>[
new Container(
alignment: Alignment.topLeft,
child: Align(
child: Text(
'Filters',
style: const TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
color: Colors.black54),
),
),
),
Spacer(), // second way
Container(
alignment: Alignment.topRight,
child: OutlineButton(
child: Text(
'Reset',
style: const TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold,
color: Colors.black54),
),
onPressed: null,
)),
])
推荐阅读
- jquery - `react/no-this-in-sfc` 当 `this` 不引用 SFC 时
- android - Android Studio Intel Haxm 安装失败
- r - 使用 case_when 附加到向量
- r - 尝试从终端 R Mac 安装 qqman 包时出错
- javascript - Javascript - 将数组拆分为带有标题的复杂部分列表
- amazon-web-services - 在近乎实时的分析中,为什么 Lambda-->Firehose-->S3 优于 Lambda-->S3?
- c# - 列表
.Clear() 与列表 = 新列表 在 C# 中(可能是 ByReference 问题?) - python - QWiget 与它的 QTreeWidgetItem 不一致
- c++ - 如何正确实现 IStream(MediaFoundation)?
- dart - dart curried 函数中的类型推断