Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 颤振增加TextFormField的高度_Android_Ios_Flutter - Fatal编程技术网

Android 颤振增加TextFormField的高度

Android 颤振增加TextFormField的高度,android,ios,flutter,Android,Ios,Flutter,我正在创建一个颤振应用程序。我是这样设计的。 我的TextFormField用于电子邮件和密码的字段高度很小。我希望它和按钮一样大 final email = TextFormField( keyboardType: TextInputType.emailAddress, autofocus: false, initialValue: 'sathyabaman@gmail.com', style: new TextStyle(fontWeight: FontW

我正在创建一个颤振应用程序。我是这样设计的。

我的TextFormField用于电子邮件和密码的字段高度很小。我希望它和按钮一样大

final email = TextFormField(
    keyboardType: TextInputType.emailAddress,
    autofocus: false,
    initialValue: 'sathyabaman@gmail.com', 
    style: new TextStyle(fontWeight: FontWeight.normal, color: Colors.white),
    decoration: InputDecoration(
      hintText: 'Email', 
      contentPadding: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0),
      border: OutlineInputBorder(
        borderRadius: BorderRadius.circular(32.0)
      ),
    ),
  );

文本表单字段中高度的语法是什么。

您可以使用此代码自定义文本表单字段

new SizedBox(
  width: 200.0,
  height: 300.0,
  child: const Card(child: const Text('Hello World!')),
)

只需在InputDecoration中调整contentPadding


除了添加额外的、永久性的填充来覆盖
errorText
,还有另一种选择,这可能会打乱许多设计师的原始项目

您可以创建的修改版本

要实现这一点,您可以:

  • 复制粘贴中的所有内容
  • 重命名自定义的
    TextFormField
    ,以避免与原始文件发生命名冲突。
    • 您可能还应该重命名内部状态类
    • 在VS代码中,您可以使用Ctrl+H替换TextFormField,例如,TextFormFieldWithErrorTextOption
  • TextFormField
    的构造函数(如下)添加另一个参数,例如,
    errorTextPresent
    /`true`是当前隐式默认值,即显示`errorText'`
    bool errorTextPresent=真
    
  • 更改内部
    文本字段的
    
  • 发件人:
    decoration:effectiveDecoration.copyWith(field.errorText)
    
  • 致:
    decoration:effectiveDecoration.copyWith(
    errorText:errorTextPresent?字段。errorText:null)
    
  • 然后,您可以像使用任何
    TextFormField
    一样使用新的
    TextFormField
    textformfield文本选项(
    errorTextPresent:false,//`false`将禁用`errorText'`
    ...
    ),
    

  • 您可以通过更改“最小线”值来更改高度,请尝试以下操作

                   TextFormField(
                               keyboardType: TextInputType.multiline,
                               controller: _opTextController,
                               decoration: InputDecoration(
                                   isDense: true,
                                 border: OutlineInputBorder(
                                   borderSide: BorderSide(color: Colors.black)
                                 )
    
                               ),
                               maxLines: 5,
                               minLines: 3,
                               // controller: cpfcontroller,
                             )
    

    只需添加一个容器。根据您的要求调整容器的高度,并使textformfield成为容器的子级。

    使用这两行来控制
    TextFormField
    内部的高度
    input装饰

    isDense: true, 
    contentPadding: EdgeInsets.fromLTRB(10, 10, 10, 0),
    
    完整示例

    Material(
                    elevation: 4,
                    shadowColor: Colors.blue,
                    shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
                    child: Padding(
                      padding: const EdgeInsets.only(left: 12),
                      child: TextFormField(
                        controller: searchProvider.searchController,
                        keyboardType: TextInputType.text,
                        decoration: InputDecoration(
                            hintText: 'hintText',
                            isDense: true, // important line
                            contentPadding: EdgeInsets.fromLTRB(10, 10, 10, 0),// control your hints text size
                            hintStyle: TextStyle(letterSpacing: 2, color: Colors.black54, fontWeight: FontWeight.bold),
                            fillColor:  Colors.white30 ,
                            filled: true,
                            border: OutlineInputBorder(borderRadius: BorderRadius.circular(30), borderSide: BorderSide.none)),
                      ),
                    ),
                  ),
    

    TextFormField
    上的
    expansed
    属性设置为
    true
    ,然后将
    TextFormField
    放入高度为
    SizedBox

    SizedBox(
       height: 40.0,
       child: TextFormField(
        keyboardType: TextInputType.emailAddress,
        autofocus: false,
        expands: true //Setting this attribute to true does the trick
        initialValue: 'sathyabaman@gmail.com', 
        style: new TextStyle(fontWeight: FontWeight.normal, color: Colors.white),
        decoration: InputDecoration(
          hintText: 'Email', 
          contentPadding: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0),
          border: OutlineInputBorder(
            borderRadius: BorderRadius.circular(32.0)
          ),
        ),
      ),
    )
    

    您可以使用
    SizedBox
    属性来更改宽度和高度如果您想添加多行,请使用
    maxLines:5
    const Cart(…)
    应该是
    new TextFormField(…)
    ,对吗?您可以用
    TextFormField
    代替
    Text('Hello World!')
    。如答案所示。在宽度值处使用double.infinity可获得动态宽度:)它不起作用,我们可以用另一种方法为文本字段指定高度吗?我想将其高度降低到小于默认高度,但它不起作用。为什么?我们如何使内容填充位于InputExtForm字段的中心?@Sokheang Khun我使用负值来减少填充,但不确定这是否是一种实用的方法。我还为此创建了一个颤振问题。很遗憾,你的答案不清楚。请为您的代码提供说明。Hey@Momoro如果您不想将静态高度传递给TextFormField,则可以使用此代码。如果minLines为1,maxlines为2,则单行TextFormField将可见,并且当用户在字段中写入更多单词时,其高度将动态增加。其高度将增加到2行,因为maxLines=2如果您最初希望显示更大的TextFormField,则增加minLines。如果你仍然不清楚,请让我知道这是我一直在寻找的。谢谢你,这是我找到的唯一降低默认高度的方法。问题是关于增加高度。不管怎样,为了减少默认大小,如果验证返回错误字符串,还必须考虑验证错误并增加高度。例如:
    容器(高度:validator==null?40:62,宽度:double.infinity,子级:TextFormField(…)
    。isDense:true work for me
    SizedBox(
       height: 40.0,
       child: TextFormField(
        keyboardType: TextInputType.emailAddress,
        autofocus: false,
        expands: true //Setting this attribute to true does the trick
        initialValue: 'sathyabaman@gmail.com', 
        style: new TextStyle(fontWeight: FontWeight.normal, color: Colors.white),
        decoration: InputDecoration(
          hintText: 'Email', 
          contentPadding: EdgeInsets.fromLTRB(20.0, 10.0, 20.0, 10.0),
          border: OutlineInputBorder(
            borderRadius: BorderRadius.circular(32.0)
          ),
        ),
      ),
    )