【发布时间】:2020-12-09 13:53:37
【问题描述】:
我试图在 Flutter 中使用可编辑文本小部件,但我无法选择、复制、剪切和粘贴,但无法使用它,我不知道为什么会发生这种情况我已启用与选择和复制粘贴,还是不行
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,
),
)
],
)
),
),
);
}
}
我希望这段代码就足够了,如果您希望我提供更多代码或者如果您有任何问题,请告诉我,谢谢!
【问题讨论】:
-
你为什么不用TextField
-
@sleepingkit 我试图在文本字段中突出显示@、# 和 URL,但我无法在普通文本字段中做到这一点