【问题标题】:flutter space between inputTextForm field and bottom borderinputTextForm 字段和底部边框之间的颤动空间
【发布时间】:2022-01-19 12:51:20
【问题描述】:

除了元素/用户输入和底栏之间的空间外,一切正常。我尝试了不同的方法来摆脱那个空间:内容填充、框约束、前缀图标约束等。没有一个工作。最终我限制了这个小部件的高度,但随后我的错误消息被放置在用户输入之上,我收到了这条消息Another exception was thrown: BoxConstraints has a negative minimum height.
代码如下:

 Widget _emailField(FormBloc formBloc) {
    return StreamBuilder(
        stream: formBloc.email,
        builder: (context, AsyncSnapshot<String> snapshot) {
          return TextFormField(
            autofocus: false,
            keyboardType: TextInputType.emailAddress,
            autovalidateMode: AutovalidateMode.onUserInteraction,
            validator: (value) {
              if (value == null) {
                return "Email cannot be empty";
              } else {
                if (value.isEmpty) {
                  return "Email cannot be empty";
                }
              }
            },
            onChanged: formBloc.changeEmail,
            textInputAction: TextInputAction.next,
            decoration: InputDecoration(
              prefixIcon: const Icon(
                Icons.email,
                size: 15,
              ),
              contentPadding: const EdgeInsets.all(0),
              labelText: "Email",
              labelStyle: const TextStyle(fontSize: 14),
              errorText:
                  snapshot.error != null ? snapshot.error as String : null,
            ),
          );
        }
      );
  }

我需要让一切都像以前一样工作,除了这次我确实需要在底部边框和输入元素之间没有空间,我该怎么做?

【问题讨论】:

    标签: flutter textfield textinput textformfield


    【解决方案1】:

    首先进入InputDecoration(),您可以将zero padding 给您的prefix icon。 然后将prefixIconConstraints 设置为BoxConstraints(maxHeight:0) 仍然不够你可以给contentPadding: EdgeInsets.only(bottom:-5), 负值。

    InputDecoration(
              prefixIcon: Padding(
                padding: EdgeInsets.only(right:10),
                child:const Icon(
                  Icons.email,
                  size: 15,
                ),
              ),
              prefixIconConstraints: BoxConstraints(maxHeight:0),
              contentPadding: EdgeInsets.only(bottom:-5),
              labelText: "Email",
              labelStyle: const TextStyle(fontSize: 14),
              errorText:"error",
            )
    

    【讨论】:

    • 这真的很有帮助,但如果你能告诉我如何移动 labeltext 那就完美了。它有点保留在旧位置并弄乱了输入字段的外观
    猜你喜欢
    • 2019-02-11
    • 1970-01-01
    • 2015-04-29
    • 1970-01-01
    • 2020-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多