简体   繁体   中英

Flutter prosperity text form field

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:

不填表

Fill case:

在此处输入图像描述

Code:

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

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;
  },
),

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:

图片1

Result after fill TextField

图片2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM