diff --git a/lib/screens/patients/profile/notes/note/update_note.dart b/lib/screens/patients/profile/notes/note/update_note.dart index 41174a15..71e86a4a 100644 --- a/lib/screens/patients/profile/notes/note/update_note.dart +++ b/lib/screens/patients/profile/notes/note/update_note.dart @@ -197,8 +197,8 @@ class _UpdateNoteOrderState extends State { .progressNote, //TranslationBase.of(context).addProgressNote, controller: progressNoteController, - maxLines: 35, - minLines: 25, + maxLines: 40, + minLines: 20, hasBorder: true, // isTextFieldHasSuffix: true, diff --git a/lib/widgets/shared/text_fields/app-textfield-custom.dart b/lib/widgets/shared/text_fields/app-textfield-custom.dart index 72d80823..1a17f315 100644 --- a/lib/widgets/shared/text_fields/app-textfield-custom.dart +++ b/lib/widgets/shared/text_fields/app-textfield-custom.dart @@ -91,6 +91,10 @@ class _AppTextFieldCustomState extends State { @override Widget build(BuildContext context) { ProjectViewModel projectViewModel = Provider.of(context); + TextInputType localKeyboardType = widget.inputType ?? + (widget.maxLines == 1 + ? TextInputType.text + : TextInputType.multiline); return Column( children: [ @@ -124,17 +128,12 @@ class _AppTextFieldCustomState extends State { crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.center, children: [ - // if ((widget.controller != null && - // widget.controller.text != "") || - // widget.dropDownText != null) + AppText( widget.hintText, - // marginTop: widget.hasHintmargin ? 0 : 30, color: Color(0xFF2E303A), fontSize: widget.isPrscription == false ? 11.0 - // SizeConfig.getHeightMultiplier() * - // (SizeConfig.isWidthLarge ? 1.1 : 1.3) : 0, fontWeight: FontWeight.w600, letterSpacing: -0.44, @@ -146,42 +145,53 @@ class _AppTextFieldCustomState extends State { widget.height != 0 && widget.maxLines == 1 ? widget.height - 22 : null, - child: TextFormField( - textAlign: projectViewModel.isArabic - ? TextAlign.right - : TextAlign.left, - focusNode: _focusNode, - textAlignVertical: TextAlignVertical.top, - decoration: TextFieldsUtils - .textFieldSelectorDecoration( - widget.hintText, null, true), - style: TextStyle( - fontSize: SizeConfig.textMultiplier * 1.7, - fontFamily: 'Poppins', - color: Color(0xFF575757), - fontWeight: FontWeight.w400, - letterSpacing: -0.56, - ), - controller: widget.controller, - keyboardType: widget.inputType ?? - (widget.maxLines == 1 - ? TextInputType.text - : TextInputType.multiline), - enabled: widget.enabled, - minLines: widget.minLines, - maxLines: widget.maxLines, - inputFormatters: - widget.inputFormatters != null - ? widget.inputFormatters - : [], - onChanged: (value) { - setState(() {}); - if (widget.onChanged != null) { - widget.onChanged(value); - } - }, - onFieldSubmitted: widget.onFieldSubmitted, - obscureText: widget.isSecure), + child: RawKeyboardListener( + focusNode: FocusNode(), + autofocus: false, + onKey: (rawKeyEvent) { + final isFormSkippedEnterEvent = rawKeyEvent is RawKeyDownEvent && + rawKeyEvent.isKeyPressed(LogicalKeyboardKey.enter); + + final needToInsertNewLine = isFormSkippedEnterEvent && + localKeyboardType == TextInputType.multiline; + if (needToInsertNewLine) { + TextEditingControllerHelper.insertText(widget.controller, '\n'); + } + }, + child: TextFormField( + textAlign: projectViewModel.isArabic + ? TextAlign.right + : TextAlign.left, + focusNode: _focusNode, + textAlignVertical: TextAlignVertical.top, + decoration: TextFieldsUtils + .textFieldSelectorDecoration( + widget.hintText, null, true), + style: TextStyle( + fontSize: SizeConfig.textMultiplier * 1.7, + fontFamily: 'Poppins', + color: Color(0xFF575757), + fontWeight: FontWeight.w400, + letterSpacing: -0.56, + ), + controller: widget.controller, + keyboardType: localKeyboardType, + enabled: widget.enabled, + minLines: widget.minLines, + maxLines: widget.maxLines, + inputFormatters: + widget.inputFormatters != null + ? widget.inputFormatters + : [], + onChanged: (value) { + setState(() {}); + if (widget.onChanged != null) { + widget.onChanged(value); + } + }, + onFieldSubmitted: widget.onFieldSubmitted, + obscureText: widget.isSecure), + ), ) : AppText( Utils.convertToTitleCase(widget.dropDownText), @@ -224,3 +234,24 @@ class _AppTextFieldCustomState extends State { ); } } + +class TextEditingControllerHelper { + static insertText(TextEditingController controller, String textToInsert) { + final selection = controller.selection; + final cursorPosition = selection.base.offset; + if (cursorPosition < 0) { + controller.text += textToInsert; + return; + } + + final text = controller.text; + final newText = + text.replaceRange(selection.start, selection.end, textToInsert); + controller.value = controller.value.copyWith( + text: newText, + selection: TextSelection.collapsed( + offset: selection.baseOffset + textToInsert.length, + ), + ); + } +} \ No newline at end of file