【问题标题】:Select text in TextField on Double Click in Flutter Windows App在 Flutter Windows 应用程序中双击选择 TextField 中的文本
【发布时间】:2022-12-03 19:32:26
【问题描述】:

在用 Flutter 制作的 Windows 应用程序中双击该字段时,是否可以选择用 TextFormField 或 TextField 编写的文本?

因为目前只有双击文本才有效,而通常在 Windows 应用程序中单击文本字段中的任意位置会选择整个文本。

【问题讨论】:

    标签: flutter flutter-textformfield flutter-windows


    【解决方案1】:

    将您的 TextField 放入 GestureDetector

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

    【讨论】:

      【解决方案2】:

      用墨水池包裹文本字段以提供双击。然后双击设置文本字段的选择

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

      【讨论】:

        【解决方案3】:

        您不需要任何其他额外的小部件。它非常简单,你可以使用点按里面的财产文本域:

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

        【讨论】:

          猜你喜欢
          • 2020-02-02
          • 1970-01-01
          • 2016-06-16
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-10-06
          • 1970-01-01
          相关资源
          最近更新 更多