首页 > 解决方案 > TextFormField 中的 Hinttext 未与前缀和后缀图标对齐

问题描述

与前缀和后缀 Icon 相比,textformfield 中的提示文本有点提升(感觉好像它与两个图标相比是向上的)。

在此处输入图像描述

我还附上了我用于此 TextFormfield 的代码:

TextFormField(
            style:
                w400.size12.copyWith(color: BrandColor.foodsearchViewTextColor),
            cursorColor: BrandColor.foodsearchViewTextColor,
            decoration: InputDecoration(
                prefixIcon: Padding(
                  padding: const EdgeInsets.only(right: 18.0),
                  child: IconButton(
                    icon: SvgPicture.asset(
                      SvgAssets.food_search_icon,
                      color: BrandColor.foodsearchViewTextColor,
                    ),
                    onPressed: null,
                  ),
                ),
                suffixIcon: Padding(
                  padding: const EdgeInsets.only(right: 14.0),
                  child: IconButton(
                    icon: SvgPicture.asset(
                      SvgAssets.food_searchview_suffix,
                      color: BrandColor.foodsearchViewTextColor,
                    ),
                    onPressed: null,
                  ),
                ),
                focusedBorder: InputBorder.none,
                enabledBorder: InputBorder.none,
                errorBorder: InputBorder.none,
                disabledBorder: InputBorder.none,
                focusedErrorBorder: InputBorder.none,
                border: InputBorder.none,
                hintText: foodSearchText,
                hintStyle: w400.size12.copyWith(
                    color: BrandColor.foodsearchViewTextColor, fontSize: 13)),
          ),

我也尝试用中心小部件包装 textformfield,但它没有解决问题。如果有人可以提供帮助,我将不胜感激

标签: flutterandroid-edittextflutter-layouttextformfieldflutter-textformfield

解决方案


您可以像这样使用contentPadding参数InputDecoration

contentPadding: EdgeInsets.symmetric(vertical: 15)

或者

contentPadding: EdgeInsets.only(top: 15)

theme您可以在 in的帮助下全局设置 contentPaddingMaterialApp

theme: ThemeData(
            inputDecorationTheme: InputDecorationTheme(
              contentPadding: EdgeInsets.symmetric(vertical: 15),
            ),
          ),

推荐阅读