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

Flutter:如何避免Row中Container增高时TextField位置上移

解决Flutter Row布局中组件对齐问题

你的问题出在Row组件默认的交叉轴对齐方式上——Row的crossAxisAlignment默认值是CrossAxisAlignment.start,这会让所有子组件沿垂直方向顶部对齐,所以右侧Container高度增加时,左侧TextField会被拉到顶部。

只需要给Row添加crossAxisAlignment属性,设置为你需要的对齐方式即可,比如垂直居中:

Padding(
  padding: const EdgeInsets.all(8.0),
  child: Row(
    // 添加这一行,设置交叉轴对齐方式
    crossAxisAlignment: CrossAxisAlignment.center,
    children: [
      Expanded(
        child: CustomTextfield(
          isPrefixIcon: false,
          bgColor: AppColors.whiteColor,
          borderColor: AppColors.blueColor,
          hintColor: AppColors.blackColor,
          isBorder: true,
          hintText: AppStrings.typeMessage,
          suffixIcon: Image.asset(AssetPaths.sendIcon,scale: 1.5,),
        ),
      ),
      sizedboxWidth5(),
      Container(
        height: 120.h,width: 40.w,
        decoration: BoxDecoration(color: AppColors.blueColor,borderRadius: BorderRadius.circular(30)),)
      
    ]
  ),
);

如果需要其他对齐效果,也可以换成CrossAxisAlignment.end(底部对齐)或者CrossAxisAlignment.stretch(拉伸填充Row高度),根据你的实际布局需求选择。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.15 04:32:06