flutter - 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,但它没有解决问题。如果有人可以提供帮助,我将不胜感激
解决方案
您可以像这样使用contentPadding
参数InputDecoration
contentPadding: EdgeInsets.symmetric(vertical: 15)
或者
contentPadding: EdgeInsets.only(top: 15)
theme
您可以在 in的帮助下全局设置 contentPaddingMaterialApp
theme: ThemeData(
inputDecorationTheme: InputDecorationTheme(
contentPadding: EdgeInsets.symmetric(vertical: 15),
),
),
推荐阅读
- python - 尝试使用 Tensorflow 加载 MNIST 数据时出错
- javascript - 变量在词法范围内不可用
- c++ - istream 重载,第二个参数是双指针?
- html - CSS 外部文件从它自己的文件夹链接到我的 html 文件
- javascript - 如何按key上的groupBy过滤对象数组?
- java - Thymeleaf 操作执行 concat 而不是 multiply
- ios - 是否可以在 Realm 迁移中重命名和更改属性的数据类型
- c# - c#静态类中的8个可为空的引用类型
- python - Argparser 返回“--mode=client --port=52085”并崩溃
- ruby-on-rails - 是否能够回滚 Stripe 更新