Flutter 颤振无法在EditableText中选择、复制或粘贴
我试图在颤振中使用一个可编辑文本小部件,但我无法选择、复制、剪切和粘贴。我不知道为什么会发生这种情况。我已经启用了与选择和复制粘贴相关的所有功能,但它仍然不起作用Flutter 颤振无法在EditableText中选择、复制或粘贴,flutter,dart,Flutter,Dart,我试图在颤振中使用一个可编辑文本小部件,但我无法选择、复制、剪切和粘贴。我不知道为什么会发生这种情况。我已经启用了与选择和复制粘贴相关的所有功能,但它仍然不起作用 class EditProfile extends StatefulWidget { @override _EditProfileState createState() => _EditProfileState(); } class _EditProfileState extends State<Edit
class EditProfile extends StatefulWidget {
@override
_EditProfileState createState() => _EditProfileState();
}
class _EditProfileState extends State<EditProfile> {
var _controller = TextEditingController();
TextSelectionControls _mainContentSelectionController;
@override
Widget _backButton() {
return InkWell(
onTap: () {
Navigator.pop(context);
},
child: Container(
padding: EdgeInsets.symmetric(horizontal: 10),
child: Row(
children: <Widget>[
Icon(
Icons.clear,
size: 30.0,
color: Color(0xff8729e6),
)
],
),
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
color: Colors.white,
child: EditableText(
controller: _controller,
toolbarOptions: ToolbarOptions(
paste: true,
copy: true,
selectAll: true,
),
readOnly : false,
focusNode: FocusNode(),
cursorColor: Colors.blue,
style: TextStyle(
color: Colors.black
),
keyboardType: TextInputType.text,
autocorrect: false,
autofocus: false,
backgroundCursorColor: Colors.red,
maxLines: 10,
minLines: 1,
enableInteractiveSelection: true,
selectionColor: Colors.red,
selectionControls: _mainContentSelectionController,
),
)
],
)
),
),
);
}
}
class EditProfile扩展StatefulWidget{
@凌驾
_EditProfileState createState()=>\u EditProfileState();
}
类_EditProfileState扩展状态{
var_controller=TextEditingController();
text selectioncontrols\u main contentselectioncontroller;
@凌驾
小部件_backButton(){
回墨槽(
onTap:(){
Navigator.pop(上下文);
},
子:容器(
填充:边缘组。对称(水平:10),
孩子:排(
儿童:[
图标(
图标。清除,
尺寸:30.0,
颜色:颜色(0xff8729e6),
)
],
),
),
);
}
@凌驾
小部件构建(构建上下文){
返回脚手架(
正文:安全区(
子:SingleChildScrollView(
子:列(
crossAxisAlignment:crossAxisAlignment.start,
儿童:[
容器(
颜色:颜色,白色,
子:可编辑文本(
控制器:_控制器,
工具栏选项:工具栏选项(
粘贴:是的,
抄袭:对,
selectAll:对,
),
只读:false,
focusNode:focusNode(),
光标颜色:颜色。蓝色,
样式:TextStyle(
颜色:颜色。黑色
),
键盘类型:TextInputType.text,
自动更正:错误,
自动对焦:错误,
背景光标颜色:Colors.red,
最大行数:10,
小姑娘:1,
enableInteractiveSelection:true,
选择颜色:Colors.red,
selectionControls:\u mainContentSelectionController,
),
)
],
)
),
),
);
}
}
我希望这个代码足够了,如果你想让我提供更多的代码或者如果你有任何问题,请告诉我,谢谢 尝试选择文本而不是简单的文本小部件。更多信息 您可以使用TextField代替可编辑文本,这段代码现在可以工作了
import 'package:flutter/material.dart';
class EditProfile extends StatefulWidget {
@override
_EditProfileState createState() => _EditProfileState();
}
class _EditProfileState extends State<EditProfile> {
var _controller = TextEditingController();
TextSelectionControls _mainContentSelectionController;
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
height: MediaQuery.of(context).size.height * 0.1,
color: Colors.white,
child: TextField(
controller: _controller,
toolbarOptions: ToolbarOptions(
paste: true,
cut: true,
copy: true,
selectAll: true,
),
readOnly: false,
focusNode: FocusNode(),
cursorColor: Colors.blue,
style: TextStyle(color: Colors.black),
keyboardType: TextInputType.text,
autocorrect: false,
autofocus: false,
maxLines: 10,
minLines: 1,
enableInteractiveSelection: true,
),
)
],
)),
),
);
}
}
导入“包装:颤振/材料.省道”;
类EditProfile扩展StatefulWidget{
@凌驾
_EditProfileState createState()=>\u EditProfileState();
}
类_EditProfileState扩展状态{
var_controller=TextEditingController();
text selectioncontrols\u main contentselectioncontroller;
@凌驾
小部件构建(构建上下文){
返回脚手架(
正文:安全区(
子:SingleChildScrollView(
子:列(
crossAxisAlignment:crossAxisAlignment.start,
儿童:[
容器(
高度:MediaQuery.of(context).size.height*0.1,
颜色:颜色,白色,
孩子:TextField(
控制器:_控制器,
工具栏选项:工具栏选项(
粘贴:是的,
切:是的,
抄袭:对,
selectAll:对,
),
只读:false,
focusNode:focusNode(),
光标颜色:颜色。蓝色,
样式:TextStyle(颜色:Colors.black),
键盘类型:TextInputType.text,
自动更正:错误,
自动对焦:错误,
最大行数:10,
小姑娘:1,
enableInteractiveSelection:true,
),
)
],
)),
),
);
}
}
根据回答,EditableText很少使用。您的代码似乎是正确的,您面临什么困难?尝试热重启一次。它在您的设备上工作吗?我已经尝试了所有方法,但我无法复制/粘贴并选择EditableText中的文本。您是否在可编辑文本中获取文本??是的,它就像一个普通的文本字段一样工作,但是我不能在里面选择文本。你可以发布你的全部代码吗?用page和所有东西?你为什么不用TextField@sleepingkit我试图在文本字段中突出显示@、#和URL,但在普通文本字段中我无法这样做