title: In Flutter the keyboard closes after being opened by clicking on the textfield of the dialogue box
body: <h2>How can I resolve this problem?.</h2>
  <p>The keyboard closes after being opened by clicking on the textfield of the dialogue box..</p>
  <p>Actually, I want to set the valid text length to 10, but when I click on the text field, it automatically unfocuse.</p>
  <p>I have used a code for doing this has been mentioned below.</p>
  <pre><code>import 'dart:ui';
  
  import 'package:bonanza_flutter/Constants/constants.dart';
  import 'package:bonanza_flutter/UIs/Dashboard/dashboard.dart';
  import 'package:flutter/cupertino.dart';
  import 'package:flutter/material.dart';
  
  class AddNewMemberPage extends StatefulWidget {
    @override
    State&lt;AddNewMemberPage&gt; createState() =&gt; _AddNewMemberPageState();
  }
  
  class _AddNewMemberPageState extends State&lt;AddNewMemberPage&gt; {
  
  
    @override
    Widget build(BuildContext context) {
      return Dialog(
        insetPadding: EdgeInsets.all(35),
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(10),
        ),
        elevation: 0.0,
        backgroundColor: Colors.transparent,
        child: dialogContent(context),
      );
    }
  }
  
  double t4Size = 14;
  
  extension widgetExtension on _AddNewMemberPageState {
  
    dialogContent(BuildContext context) {
      GlobalKey&lt;FormState&gt; _formKey = GlobalKey();
      TextEditingController addPanController = TextEditingController();
      return SingleChildScrollView(
        child: BackdropFilter(
          filter: ImageFilter.blur(sigmaX: 3.3, sigmaY: 3.3),
          child: Dialog(
            insetPadding: EdgeInsets.only(top: 30, bottom: 30, left: 20, right: 20),
            shape:
            RoundedRectangleBorder(borderRadius: BorderRadius.circular(15.0)),
            // backgroundColor: skyBlue,
            child: Container(
                padding: EdgeInsets.only(top: 30, bottom: 30),
                decoration: new BoxDecoration(
                  color: Colors.white,
                  shape: BoxShape.rectangle,
                  borderRadius: BorderRadius.circular(10),
                  boxShadow: [
                    BoxShadow(
                      color: Colors.black26,
                      blurRadius: 10.0,
                      offset: const Offset(0.0, 10.0),
                    ),
                  ],
                ),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    Text(
                      &quot;Add New Member&quot;,
                      style: TextStyle(
                          fontSize: tSize26,
                          color: skyBlue,
                          fontWeight: FontWeight.w500),
                      textAlign: TextAlign.center,
                    ),
                    Form(
                      key: _formKey,
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
  
                          Padding(
                            padding:
                            const EdgeInsets.only(left: 20.0, right: 20, bottom: 4,top: 20),
                            child: Text(
                              &quot;PAN Card&quot;,
                              style: TextStyle(
                                fontSize: tSize14,
                                color: darkGreyColor,
                                fontWeight: FontWeight.w500,
                              ),
                            ),
                          ),
                          Padding(
                            padding: const EdgeInsets.only(
                                left: 20.0, right: 20, bottom: 20),
                            child: TextFormField(
                              onChanged: (value) {
                                if (value.length == 10) {
                                  FocusScope.of(context).unfocus();
                                }
  
                              },
                              validator: (value) {
                                if (value!.length == 10) {
                                  return null;
                                }
                                return &quot;&quot;;
                              },
                              maxLength: 10,
  
                              textCapitalization: TextCapitalization.characters,
                              controller: addPanController,
                              cursorColor: Theme.of(context).cursorColor,
                              decoration: const InputDecoration(
                                counterText: &quot;&quot;,
                                hintText: &quot;Enter PAN number&quot;,
                                hintStyle: TextStyle(color: greyColor),
                                enabledBorder: UnderlineInputBorder(
  
                                  borderSide:
                                  BorderSide(color: mediumGreyColor, width: 1.7),
                                ),
                                contentPadding:
                                EdgeInsets.only(left: 12, right: 12, top: 12),
                                focusedBorder: UnderlineInputBorder(
                                  borderSide:
                                  BorderSide(color: mediumGreyColor, width: 1.7),
                                ),
                                prefixIcon: Icon(
                                  Icons.verified_user_rounded,
                                  color: greyColor,
                                ),
                              ),
                            ),
                          )
                          
                        ],
                      ),
                    ),
  
                    Padding(
                      padding: const EdgeInsets.all(20.0),
                      child: Text(
                        &quot;Note: PAN number should be connected to same phone number by which you currently sign in.&quot;,
                        style: TextStyle(
                          fontSize: tSize14,
                          color: greyColor,
                        ),
                        textAlign: TextAlign.center,
                      ),
                    ),
                    Padding(
                      padding: const EdgeInsets.only(
                          top: 00.0, bottom: 4, left: 30, right: 30),
                      child: SizedBox(
                        height: 45,
                        width: MediaQuery.of(context).size.width,
                        child: ElevatedButton(
                          style: ElevatedButton.styleFrom(
                              primary: skyBlue, shadowColor: Colors.transparent),
                          onPressed: () {
                            Navigator.pop(context);
                            Navigator.push(
                                context,
                                (MaterialPageRoute(
                                    builder: (context) =&gt; Dashboard())));
                          },
                          child: Text(
                            'Add Member',
                            style: TextStyle(
                              fontSize: tSize16,
                            ),
                          ),
                        ),
                      ),
                    ),
                  ],
                )),
          ),
        ),
      );
    }
  }
  
  </code></pre>
  <p>this is my on click fuction</p>
  <pre><code>             showDialog(
                    useRootNavigator: true,
                    barrierDismissible: false,
                    barrierColor: skyBlue.withOpacity(0.4),
                    context: context,
                    builder: (BuildContext context) {
                      return AddNewMemberPage();
                    });
  </code></pre>