How to change TextField's height and width?

后端 未结 7 1659
既然无缘
既然无缘 2020-12-13 08:02

How to customise TextField\'s width and height?

相关标签:
7条回答
  • 2020-12-13 08:36

    I think you want to change the inner padding/margin of the TextField.

    You can do that by adding isDense: true and contentPadding: EdgeInsets.all(8) properties as follow:

    Container(
      padding: EdgeInsets.all(12),
      child: Column(
        children: <Widget>[
          TextField(
            decoration: InputDecoration(
              border: OutlineInputBorder(),
              labelText: 'Default TextField',
            ),
          ),
          SizedBox(height: 16,),
          TextField(
            decoration: InputDecoration(
              border: OutlineInputBorder(),
              labelText: 'Densed TextField',
              isDense: true,                      // Added this
            ),
          ),
          SizedBox(height: 16,),
          TextField(
            decoration: InputDecoration(
              border: OutlineInputBorder(),
              labelText: 'Even Densed TextFiled',
              isDense: true,                      // Added this
              contentPadding: EdgeInsets.all(8),  // Added this
            ),
          )
        ],
      ),
    )
    

    It will be displayed as:

    0 讨论(0)
  • 2020-12-13 08:39

    If you use "suffixIcon" to collapse the height of the TextField add: suffixIconConstraints

    TextField(
                        style: TextStyle(fontSize: r * 1.8, color: Colors.black87),
                        decoration: InputDecoration(
                          isDense: true,
                          contentPadding: EdgeInsets.symmetric(vertical: r * 1.6, horizontal: r * 1.6),
                          suffixIcon: Icon(Icons.search, color: Colors.black54),
                          suffixIconConstraints: BoxConstraints(minWidth: 32, minHeight: 32),
                        ),
                      )
    
    0 讨论(0)
  • 2020-12-13 08:50

    Screenshot:


    Widget _buildTextField() {
      final maxLines = 5;
    
      return Container(
        margin: EdgeInsets.all(12),
        height: maxLines * 24.0,
        child: TextField(
          maxLines: maxLines,
          decoration: InputDecoration(
            hintText: "Enter a message",
            fillColor: Colors.grey[300],
            filled: true,
          ),
        ),
      );
    }
    
    0 讨论(0)
  • 2020-12-13 08:51

    TextField( minLines: 1, maxLines: 5, maxLengthEnforced: true)

    0 讨论(0)
  • 2020-12-13 08:54

    You can try the margin property in the Container. Wrap the TextField inside a Container and adjust the margin property.

    new Container(
      margin: const EdgeInsets.only(right: 10, left: 10),
      child: new TextField( 
        decoration: new InputDecoration(
          hintText: 'username',
          icon: new Icon(Icons.person)),
      )
    ),
    
    0 讨论(0)
  • 2020-12-13 08:54

    To increase the height of TextField Widget just make use of the maxLines: properties that comes with the widget. For Example: TextField( maxLines: 5 ) // it will increase the height and width of the Textfield.

    0 讨论(0)
提交回复
热议问题