gpt4 book ai didi

flutter - Flutter无法选择,复制或粘贴EditableText

转载 作者:行者123 更新时间:2023-12-03 04:39:28 26 4
gpt4 key购买 nike

我试图在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,

),
)
],
)
),
),
);
}
}
我希望此代码足够,如果您希望我提供更多代码或有任何疑问,请告诉我,谢谢!

最佳答案

尝试“可选文本”,而不是简单文本小部件。更多信息here
您可以使用TextField而不是Editable Text,此代码现在有效。

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,
),
)
],
)),
),
);
}
}
按照 this的回答,很少使用EditableText。

关于flutter - Flutter无法选择,复制或粘贴EditableText,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63501492/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com