You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter中如何将TextField与列内其余元素顶部对齐

解决TextField顶部对齐问题

要让Weight TextField和右侧绿色列顶部对齐,同时保留原有宽度,只需修改Row的垂直对齐方式:

Row默认的crossAxisAlignment是CrossAxisAlignment.center,会把所有子元素垂直居中排列。将其改为CrossAxisAlignment.start,就能让所有子元素靠顶部对齐,同时Expanded的flex属性会维持各列的宽度比例。

修改后的完整代码:

Row(
  crossAxisAlignment: CrossAxisAlignment.start, // 添加顶部对齐配置
  children: [
    Expanded(
        flex: 1,
        child: Container(
          color: Colors.indigo,
          height: 50,
          child: const TextField(
            decoration: InputDecoration(
              labelText: 'Weight',
              border: OutlineInputBorder(),
            ),
          ),
        )),
    Expanded(
        flex: 3, child: Container(color: Colors.teal, height: 100)),
    Expanded(
      child: Container(
        height: 100,
        child: Column(
          children: [
            Row(children: [
              Text("test1", style: TextStyle(fontSize: 25)),
              Text("test1")
            ]),
            Row(children: [Text("test2"), Text("test2")])
          ],
        ),
      ),
    ),
  ],
),

内容的提问来源于stack exchange,提问作者kumar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 04:32:40