TextFormField Flutter 中的前缀位置和大小 [英] Prefix position and size in TextFormField Flutter

查看:19
本文介绍了TextFormField Flutter 中的前缀位置和大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让前缀与输入字段对齐而不是那样浮动?

is there any way to make the prefix is aligned with the input field and not floating like that?

这是我的代码

                   TextFormField(
                        autovalidateMode: AutovalidateMode.always,
                        keyboardType: TextInputType.phone,
                        controller: noHpField,
                        decoration: const InputDecoration(
                          isDense: true,
                          prefixIcon:Text("+62", style: TextStyle(fontSize: 12, fontWeight: FontWeight.bold)),
                          prefixIconConstraints: BoxConstraints(minWidth: 0, minHeight: 0),
                          icon: Icon(Icons.phone_android),
                          labelText: 'No HP',
                        ),
                        validator: (String? value) {
                          if (value == null || value.isEmpty) {
                            return 'Mohon Isikan Data';
                          }
                          return null;
                        },
                      ),

推荐答案

  TextFormField(
             autovalidateMode: AutovalidateMode.always,
              keyboardType: TextInputType.phone,
              controller: noHpField,
               decoration: const InputDecoration(
                border: OutlineInputBorder(),
                isDense: true,
                prefixIcon: Text("+62",
                style: TextStyle(
                           fontSize: 12,
                            fontWeight: FontWeight.bold)),
                                      prefixIconConstraints: 
                                  BoxConstraints(
                                     [![enter image description here][1]][1] minWidth: 0, minHeight: 0),
                                      icon: Icon(Icons.phone_android),
                                      labelText: 'No HP',
                                    ),
                                    validator: (String? value) {
                                      if (value == null || value.isEmpty) {
                                        return 'Mohon Isikan Data';
                                      }
                                      return null;
                                    },
                                  ),

您可以在 prefixIcon 中使用 Padding 属性使其看起来更整洁.

You can use Padding property in the prefixIcon to make it look more neat.

这篇关于TextFormField Flutter 中的前缀位置和大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆