0

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

1 Answer 1

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 :-

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.