From edfe5f9e71677a3d2a9bd71eea94d77a549a7e5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Bachi?= Date: Wed, 18 Sep 2019 13:37:39 -0300 Subject: [PATCH] Fix changin a character in the middle of the text --- lib/flutter_masked_text.dart | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/flutter_masked_text.dart b/lib/flutter_masked_text.dart index e75adf9..77ea287 100644 --- a/lib/flutter_masked_text.dart +++ b/lib/flutter_masked_text.dart @@ -58,10 +58,16 @@ class MaskedTextController extends TextEditingController { } @override - void set text(String newText) { + set text(String newText) { + print(newText); if (super.text != newText) { - super.text = newText; - this.moveCursorToEnd(); + int position = this.selection.baseOffset >= super.text.length + ? (newText ?? '').length + : this.selection.baseOffset; + value = value.copyWith( + text: newText, + selection: TextSelection.collapsed(offset: position), + composing: TextRange.empty); } }