简体   繁体   中英

how enable TextFormField input flutter

I'm starter in Flutter and Dart.I created TextFormField input, I would like to make it enable but i can't do that.As you see i tried to use some solutions but they couldn't help me, it's always disable. Ho i can fix it? Any help please?

My code:

 body: Directionality(
        textDirection: TextDirection.ltr,
        child: Stack(
          children: <Widget>[
            Container(
              color: Colors.white,
              height: MediaQuery.of(context).size.height,
              width: MediaQuery.of(context).size.width,
            ),
            Positioned(
                bottom: 0,
                child: Container(
                  height: 60,
                  width: MediaQuery.of(context).size.width,
                  child: Column(
                    children: <Widget>[
                      Container(
                        decoration: BoxDecoration(
                            border:
                                Border(top: BorderSide(color: Colors.grey))),
                        child: Row(
                          children: <Widget>[
                            IconButton(
                                icon: Icon(
                                  Icons.camera_enhance,
                                  color: Colors.grey,
                                ),
                                onPressed: () {}),
                            Container(
                                padding: EdgeInsets.symmetric(
                                    horizontal: 5, vertical: 5),
                                width: MediaQuery.of(context).size.width - 50,
                                child: TextFormField(
                                 // enabled: true,
                                 //  readOnly: false,
                                //  enableInteractiveSelection: true,
                                  controller: _addcomment,
                                  decoration: InputDecoration(
                                    hintText: 'Type something',
                                    filled: true,
                                    fillColor: Colors.grey[200],
                                    suffixIcon: IconButton(
                                      icon: Icon(Icons.send),
                                      onPressed: addComment,
                                    ),
                                    contentPadding: EdgeInsets.all(5),
                                    focusedBorder: OutlineInputBorder(
                                        borderRadius: BorderRadius.circular(60),
                                        borderSide: BorderSide(
                                            style: BorderStyle.none)),
                                    enabledBorder: OutlineInputBorder(
                                        borderRadius: BorderRadius.circular(60),
                                        borderSide: BorderSide(
                                            style: BorderStyle.none)),
                                    errorBorder: InputBorder.none,
                                    disabledBorder: InputBorder.none,
                                  ),
                                )),
                          ],
                        ),
                      )
                    ],
                  ),
                )),

and this TextFormField Input

在此处输入图像描述

add property autoFocus and set it's value as a true.

Here is Your Correct Code:

 body: Directionality(
            textDirection: TextDirection.ltr,
            child: Stack(
              children: <Widget>[
                Container(
                  color: Colors.white,
                  height: MediaQuery.of(context).size.height,
                  width: MediaQuery.of(context).size.width,
                ),
                Positioned(
                    bottom: 0,
                    child: Container(
                      height: 60,
                      width: MediaQuery.of(context).size.width,
                      child: Column(
                        children: <Widget>[
                          Container(
                            decoration: BoxDecoration(
                                border:
                                    Border(top: BorderSide(color: Colors.grey))),
                            child: Row(
                              children: <Widget>[
                                IconButton(
                                    icon: Icon(
                                      Icons.camera_enhance,
                                      color: Colors.grey,
                                    ),
                                    onPressed: () {}),
                                Container(
                                    padding: EdgeInsets.symmetric(
                                        horizontal: 5, vertical: 5),
                                    width: MediaQuery.of(context).size.width - 50,
                                    child: TextFormField(
                                    autoFocus: true,
                                      controller: _addcomment,
                                      decoration: InputDecoration(
                                        hintText: 'Type something',
                                        filled: true,
                                        fillColor: Colors.grey[200],
                                        suffixIcon: IconButton(
                                          icon: Icon(Icons.send),
                                          onPressed: addComment,
                                        ),
                                        contentPadding: EdgeInsets.all(5),
                                        focusedBorder: OutlineInputBorder(
                                            borderRadius: BorderRadius.circular(60),
                                            borderSide: BorderSide(
                                                style: BorderStyle.none)),
                                        enabledBorder: OutlineInputBorder(
                                            borderRadius: BorderRadius.circular(60),
                                            borderSide: BorderSide(
                                                style: BorderStyle.none)),
                                        errorBorder: InputBorder.none,
                                        disabledBorder: InputBorder.none,
                                      ),
                                    )),
                              ],
                            ),
                          )
                        ],
                      ),
                    )),

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