已解决: TextFormField中的复制和粘贴无法正常工作
我发现我在使用Listener
的onPointerDown方法来移除焦点,以便用户在应用程序其他任何地方单击时失去焦点。但这会引起错误。
但现在问题是如何在其他地方单击以删除焦点。
Listener(
onPointerDown: (_) {
FocusScopeNode currentFocus = FocusScope.of(context);
if (!currentFocus.hasPrimaryFocus &&
currentFocus.focusedChild != null) {
currentFocus.focusedChild.unfocus();
}
},)
我尝试在我的Flutter应用程序中的TextFormField
中实现复制和粘贴功能。我尝试了很多方法,但仍然无法正常工作。
这是我的代码
Widget textFormWidget(
String label, TextEditingController controller, bool enabled) {
return Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
enabled: true,
enableInteractiveSelection: true,
readOnly: false,
toolbarOptions:
ToolbarOptions(paste: true, cut: true, selectAll: true, copy: true),
textAlign: TextAlign.center,
cursorColor: Colors.white,
cursorWidth: 3,
controller: controller,
style: bold.copyWith(fontSize: 18),
decoration: InputDecoration(
focusColor: Colors.white,
hoverColor: Colors.white,
labelText: label,
alignLabelWithHint: true,
labelStyle: normal),
),
);
}
将其作为textFormWidget('Name', nameController, true)
调用。
如果您需要更多的代码或信息,请留言。
ToolBarOptions
的内部代码,你可以在那里读到它没有启用。 - DIVYANSHU SAHU