From 04d920bd3bda90157a9a0d706348192dc38968b0 Mon Sep 17 00:00:00 2001 From: Ankit Mahato Date: Mon, 13 Mar 2023 02:58:57 +0530 Subject: [PATCH] Update editor.dart --- lib/widgets/editor.dart | 78 ++++++++++++++++++++++++++++++++++------- 1 file changed, 66 insertions(+), 12 deletions(-) diff --git a/lib/widgets/editor.dart b/lib/widgets/editor.dart index bcbaf876..33ac1e21 100644 --- a/lib/widgets/editor.dart +++ b/lib/widgets/editor.dart @@ -18,13 +18,8 @@ class TextFieldEditor extends StatefulWidget { class _TextFieldEditorState extends State { final TextEditingController controller = TextEditingController(); - final editorFocusNode = FocusNode(); - final keyboardListnerFocusNode = FocusNode(); - - @override - void initState() { - super.initState(); - } + late final FocusNode editorFocusNode; + late final FocusNode keyboardListnerFocusNode; void insertTab() { String sp = " "; @@ -42,6 +37,22 @@ class _TextFieldEditorState extends State { ); } + @override + void initState() { + super.initState(); + editorFocusNode = FocusNode(debugLabel: "Editor Focus Node"); + keyboardListnerFocusNode = + FocusNode(debugLabel: "Keyboard Listner Focus Node"); + } + + @override + void dispose() { + keyboardListnerFocusNode.dispose(); + editorFocusNode.dispose(); + super.dispose(); + } + + /* @override Widget build(BuildContext context) { if (widget.initialValue != null) { @@ -55,6 +66,11 @@ class _TextFieldEditorState extends State { if (kIsWeb) { FocusScope.of(context).previousFocus(); } else { + print(FocusScope.of(context).debugLabel); + print("here"); + //FocusScope.of(context).requestFocus(editorFocusNode); + //FocusScope.of(context).previousFocus(); + //FocusScope.of(context).unfocus(); editorFocusNode.requestFocus(); } insertTab(); @@ -92,12 +108,50 @@ class _TextFieldEditorState extends State { ), ), ); - } + }*/ @override - void dispose() { - keyboardListnerFocusNode.dispose(); - editorFocusNode.dispose(); - super.dispose(); + Widget build(BuildContext context) { + if (widget.initialValue != null) { + controller.text = widget.initialValue!; + } + return CallbackShortcuts( + bindings: { + const SingleActivator(LogicalKeyboardKey.tab): () { + insertTab(); + }, + }, + child: TextFormField( + key: Key(widget.fieldKey), + controller: controller, + focusNode: editorFocusNode, + keyboardType: TextInputType.multiline, + expands: true, + maxLines: null, + style: kCodeStyle, + textAlignVertical: TextAlignVertical.top, + onChanged: widget.onChanged, + decoration: InputDecoration( + hintText: "Enter content (body)", + hintStyle: TextStyle( + color: Theme.of(context).colorScheme.outline.withOpacity( + kHintOpacity, + ), + ), + focusedBorder: OutlineInputBorder( + borderSide: BorderSide( + color: Theme.of(context).colorScheme.primary.withOpacity( + kHintOpacity, + ), + ), + ), + enabledBorder: OutlineInputBorder( + borderSide: BorderSide( + color: Theme.of(context).colorScheme.surfaceVariant, + ), + ), + ), + ), + ); } }