Search code examples
flutterflutter-textformfield

Keyboard is poping and fading out in 1 sec after i click my text field


I have made this code by learning on youtube and now i did same as the youtube tutorial goes by in my phone as soon as i click the text field my keyboard pops out but it fades again in 1 secs feels like someone is pushing it back as soon as i click the text field someone help me with this

` Widget build(BuildContext context) {
    final controller = Get.put(SignUpController());
    final _formkey = GlobalKey<FormState>();
    return Container(
      padding: const EdgeInsets.symmetric(vertical: tFormHeight - 10),
      child: Form(
        key: _formkey,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            TextFormField(
              controller: controller.fullName,
              decoration: const InputDecoration(
                label: Text(tFullName),
                prefixIcon: Icon(Icons.person_outline_rounded),
              ),
            ),
            SizedBox(height: tFormHeight - 20),
            TextFormField(
              // onTap: () {
              //   FocusNode.requestFocus();
              // },
              // keyboardType: TextInputType.numberWithOptions(signed: true),
              // inputFormatters: [
              //   FilteringTextInputFormatter.digitsOnly,
              // ],
              controller: controller.email,
              decoration: const InputDecoration(
                label: Text(TEmail),
                prefixIcon: Icon(Icons.email_outlined),
              ),
            ),
            SizedBox(height: tFormHeight - 20),
            TextFormField(
              controller: controller.phoneNo,
              decoration: const InputDecoration(
                label: Text(tPhone),
                prefixIcon: Icon(Icons.numbers),
              ),
            ),
            SizedBox(height: tFormHeight - 20),
            TextFormField(
              controller: controller.password,
              decoration: const InputDecoration(
                label: Text(TPassword),
                prefixIcon: Icon(Icons.fingerprint),
              ),
            ),
            SizedBox(height: tFormHeight - 20),
            SizedBox(
              width: double.infinity,
              child: ElevatedButton(
                onPressed: () {
                  if (_formkey.currentState!.validate()) {
                    SignUpController.Instance.registerUser(
                        controller.email.text.trim(),
                        controller.password.text.trim());
                  }
                },
                child: Text(
                  tSignup.toUpperCase(),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

Help me to overcome this problem due to this my project is declining its deadline and i have to put this in my resume Thanks for reading till this.


Solution

  • You need to define your form key and controller outside of your build function

    final controller = Get.put(SignUpController());
    final _formkey = GlobalKey<FormState>();
    
    Widget build(BuildContext context) {
        return Container(
        ...