fix the keyborad issue on real device

merge-requests/991/head
Elham Rababh 4 years ago
parent 31082249e5
commit 8c93d5c450

@ -197,8 +197,8 @@ class _UpdateNoteOrderState extends State<UpdateNoteOrder> {
.progressNote, .progressNote,
//TranslationBase.of(context).addProgressNote, //TranslationBase.of(context).addProgressNote,
controller: progressNoteController, controller: progressNoteController,
maxLines: 35, maxLines: 40,
minLines: 25, minLines: 20,
hasBorder: true, hasBorder: true,
// isTextFieldHasSuffix: true, // isTextFieldHasSuffix: true,

@ -91,6 +91,10 @@ class _AppTextFieldCustomState extends State<AppTextFieldCustom> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
ProjectViewModel projectViewModel = Provider.of(context); ProjectViewModel projectViewModel = Provider.of(context);
TextInputType localKeyboardType = widget.inputType ??
(widget.maxLines == 1
? TextInputType.text
: TextInputType.multiline);
return Column( return Column(
children: [ children: [
@ -124,17 +128,12 @@ class _AppTextFieldCustomState extends State<AppTextFieldCustom> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
// if ((widget.controller != null &&
// widget.controller.text != "") ||
// widget.dropDownText != null)
AppText( AppText(
widget.hintText, widget.hintText,
// marginTop: widget.hasHintmargin ? 0 : 30,
color: Color(0xFF2E303A), color: Color(0xFF2E303A),
fontSize: widget.isPrscription == false fontSize: widget.isPrscription == false
? 11.0 ? 11.0
// SizeConfig.getHeightMultiplier() *
// (SizeConfig.isWidthLarge ? 1.1 : 1.3)
: 0, : 0,
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
letterSpacing: -0.44, letterSpacing: -0.44,
@ -146,42 +145,53 @@ class _AppTextFieldCustomState extends State<AppTextFieldCustom> {
widget.height != 0 && widget.maxLines == 1 widget.height != 0 && widget.maxLines == 1
? widget.height - 22 ? widget.height - 22
: null, : null,
child: TextFormField( child: RawKeyboardListener(
textAlign: projectViewModel.isArabic focusNode: FocusNode(),
? TextAlign.right autofocus: false,
: TextAlign.left, onKey: (rawKeyEvent) {
focusNode: _focusNode, final isFormSkippedEnterEvent = rawKeyEvent is RawKeyDownEvent &&
textAlignVertical: TextAlignVertical.top, rawKeyEvent.isKeyPressed(LogicalKeyboardKey.enter);
decoration: TextFieldsUtils
.textFieldSelectorDecoration( final needToInsertNewLine = isFormSkippedEnterEvent &&
widget.hintText, null, true), localKeyboardType == TextInputType.multiline;
style: TextStyle( if (needToInsertNewLine) {
fontSize: SizeConfig.textMultiplier * 1.7, TextEditingControllerHelper.insertText(widget.controller, '\n');
fontFamily: 'Poppins', }
color: Color(0xFF575757), },
fontWeight: FontWeight.w400, child: TextFormField(
letterSpacing: -0.56, textAlign: projectViewModel.isArabic
), ? TextAlign.right
controller: widget.controller, : TextAlign.left,
keyboardType: widget.inputType ?? focusNode: _focusNode,
(widget.maxLines == 1 textAlignVertical: TextAlignVertical.top,
? TextInputType.text decoration: TextFieldsUtils
: TextInputType.multiline), .textFieldSelectorDecoration(
enabled: widget.enabled, widget.hintText, null, true),
minLines: widget.minLines, style: TextStyle(
maxLines: widget.maxLines, fontSize: SizeConfig.textMultiplier * 1.7,
inputFormatters: fontFamily: 'Poppins',
widget.inputFormatters != null color: Color(0xFF575757),
? widget.inputFormatters fontWeight: FontWeight.w400,
: [], letterSpacing: -0.56,
onChanged: (value) { ),
setState(() {}); controller: widget.controller,
if (widget.onChanged != null) { keyboardType: localKeyboardType,
widget.onChanged(value); enabled: widget.enabled,
} minLines: widget.minLines,
}, maxLines: widget.maxLines,
onFieldSubmitted: widget.onFieldSubmitted, inputFormatters:
obscureText: widget.isSecure), widget.inputFormatters != null
? widget.inputFormatters
: [],
onChanged: (value) {
setState(() {});
if (widget.onChanged != null) {
widget.onChanged(value);
}
},
onFieldSubmitted: widget.onFieldSubmitted,
obscureText: widget.isSecure),
),
) )
: AppText( : AppText(
Utils.convertToTitleCase(widget.dropDownText), Utils.convertToTitleCase(widget.dropDownText),
@ -224,3 +234,24 @@ class _AppTextFieldCustomState extends State<AppTextFieldCustom> {
); );
} }
} }
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,
),
);
}
}
Loading…
Cancel
Save