admin管理员组

文章数量:1289507

This is the goal This is what i made

I can't customize properly the behaviour of the label text

Container(
  width: 270,
  height: 40,
  decoration: BoxDecoration(
    color: const Color.fromARGB(255, 243, 250, 220),
    borderRadius: BorderRadius.circular(20),
    border: Border.all(color: Colors.green),
  ),
  child: TextFormField(
    controller: _emailController,
    textAlign: TextAlign.left,
    decoration: const InputDecoration(
      labelText: 'USERNAME OR EMAIL',
      floatingLabelBehavior: FloatingLabelBehavior.auto,
      floatingLabelAlignment:
          FloatingLabelAlignment.start,
      border: InputBorder.none,
      labelStyle: TextStyle(
          fontSize: 10,
          fontFamily: 'Montserrat',
          fontWeight: FontWeight.normal,
          letterSpacing: 0.4,
          color: const Color.fromARGB(255, 88, 88, 88)),
      contentPadding: EdgeInsets.symmetric(
          horizontal: 20, vertical: 18),
    ),
    validator: (value) {
      if (value == null || value.isEmpty) {
        return 'Please enter your email';
      }
      return null;
    },
  ),
),

Basically, I want the label text to move to the uppermost left of the textbox when i click it, so I can type the input without the label text disappearing ang obstructing the input

This is the goal This is what i made

I can't customize properly the behaviour of the label text

Container(
  width: 270,
  height: 40,
  decoration: BoxDecoration(
    color: const Color.fromARGB(255, 243, 250, 220),
    borderRadius: BorderRadius.circular(20),
    border: Border.all(color: Colors.green),
  ),
  child: TextFormField(
    controller: _emailController,
    textAlign: TextAlign.left,
    decoration: const InputDecoration(
      labelText: 'USERNAME OR EMAIL',
      floatingLabelBehavior: FloatingLabelBehavior.auto,
      floatingLabelAlignment:
          FloatingLabelAlignment.start,
      border: InputBorder.none,
      labelStyle: TextStyle(
          fontSize: 10,
          fontFamily: 'Montserrat',
          fontWeight: FontWeight.normal,
          letterSpacing: 0.4,
          color: const Color.fromARGB(255, 88, 88, 88)),
      contentPadding: EdgeInsets.symmetric(
          horizontal: 20, vertical: 18),
    ),
    validator: (value) {
      if (value == null || value.isEmpty) {
        return 'Please enter your email';
      }
      return null;
    },
  ),
),

Basically, I want the label text to move to the uppermost left of the textbox when i click it, so I can type the input without the label text disappearing ang obstructing the input

Share Improve this question edited Feb 20 at 4:44 Frank van Puffelen 600k85 gold badges889 silver badges859 bronze badges asked Feb 20 at 3:25 Cedric Gian C. CombateCedric Gian C. Combate 434 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

All you had to do was to give padding to the label property by wrapping it by Padding Widget.

Full Code : -

Container(
        width: 270,
        decoration: BoxDecoration(
          color: const Color.fromARGB(255, 243, 250, 220),
          border: Border.all(color: Colors.green),
          borderRadius: BorderRadius.all(Radius.circular(25)),
        ),
        child: TextFormField(
          decoration: InputDecoration(
            border: InputBorder.none,
            label: Padding(
              padding: EdgeInsets.only(bottom: 5),
              child: Text('USERNAME OR EMAIL'),
            ),

            labelStyle: TextStyle(
              fontSize: 10,
              fontFamily: 'Montserrat',
              fontWeight: FontWeight.normal,
              letterSpacing: 0.4,
              color: const Color.fromARGB(255, 88, 88, 88),
            ),
            contentPadding: EdgeInsets.symmetric(horizontal: 20, vertical: 5),
          ),
        ),
      )

Output :-

本文标签: Text form field label text behaviourflutter dartStack Overflow