Saad Bashir
Saad Bashir

Reputation: 4519

Select text in TextField on Double Click in Flutter Windows App

Is there an option to select the text written in TextFormField or TextField on double clicking the field in a Windows App made in Flutter?

Because currently it only works if the text is double clicked, whereas normally in windows application clicking anywhere in the text field selects the entire text written.

Upvotes: 3

Views: 3700

Answers (3)

Hossein Vejdani
Hossein Vejdani

Reputation: 1108

You Dont need any other extra Widgets. Its pretty simple,You can use onTap property inside of TextField:

TextField(
   controller: _controller,
   onTap: () {
     _controller.selection = TextSelection(baseOffset: 0, extentOffset: _controller.text.length);
   }
)

Upvotes: 0

Amroun
Amroun

Reputation: 455

Put your TextField inside GestureDetector

GestureDetector(
   onDoubleTap:() {
     if(_controller.text.isNotEmpty) {
       _controller.selection = TextSelection(baseOffset: 0, extentOffset:_controller.text.length);
     }
   },
   child: TextField(controller: _controller, ),
)

Upvotes: 3

Kaushik Chandru
Kaushik Chandru

Reputation: 17732

Wrap the textfield with an inkwell to provide a double tap. Then on double tap set the selection of the textfield

InkWell(
 onDoubleTap:(){
   setState((){
      _textController.selection = TextSelection(baseOffset:0, extentOffset: _textController.text.length);
   });
  },
 child:TextField(
  controller: _textController,
 )
)

Upvotes: 1

Related Questions