Home > Software engineering >  Flutter prosperity text form field
Flutter prosperity text form field

Time:01-11

I want to build a textFormFeild so that it is like the one in the image below, in addition to that I can control its properties such as default textFormFeild and it is responsive.

In the case of focus, the background color is changed. I want to build a costume.

Empty case:

not fill case

Fill case:

enter image description here

Code:

TextFormField(
  keyboardType: TextInputType.emailAddress,
  decoration: const InputDecoration(hintText: 'Enter Your Email'),
)

CodePudding user response:

Try below code hope its help to you, I have try same

Variable Declaration:

 TextEditingController textEditingController = TextEditingController();
  bool isTextEmpty = false;

Widget:

Container(
  padding:const EdgeInsets.only(top: 10, left: 15),
  height: 60,
  decoration: BoxDecoration(
    color: isTextEmpty ? Colors.white : Colors.grey.shade200,
    borderRadius: BorderRadius.circular(10),
    border: Border.all(
      color: isTextEmpty ? Colors.red : Colors.grey.shade300,
    ),
  ),
  child: Column(
    crossAxisAlignment: CrossAxisAlignment.start,
    children: [
      const Text('Email'),
      TextField(
        controller: textEditingController,
        onChanged: (value) {
          setState(() {
            if (value.length > 0) {
              isTextEmpty = true;
            } else {
              isTextEmpty = false;
            }
          });
        },
        decoration: const InputDecoration(
            isDense: true,
            border: InputBorder.none,
            hintText: 'Enter Email Here',),
      ),
    ],
  ),
),

Result before empty TextField:

image1

Result after fill TextField

image2

CodePudding user response:

You need to check the validation process as follows.

TextFormField(
  // The validator receives the text that the user has entered.
  validator: (value) {
    if (value == null || value.isEmpty) {
      return 'Please enter some text';
    }
    return null;
  },
),
  • Related