Home > Mobile >  Select text in TextField on Double Click in Flutter Windows App
Select text in TextField on Double Click in Flutter Windows App

Time:07-13

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.

CodePudding user response:

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

CodePudding user response:

Put your TextField inside GestureDetector

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