From 62d5e1ddd0f2e3917caaa573a58e4d9b4c5b6c37 Mon Sep 17 00:00:00 2001 From: Jorel Cruz Date: Thu, 19 Aug 2021 17:17:45 +0800 Subject: [PATCH 1/2] - update Chips_input.dart - Wrapped notificationListener with RawKeyboardListener to fix bug for android devices --- .../contents.xcworkspacedata | 2 +- lib/src/chips_input.dart | 71 +++++++++++-------- 2 files changed, 43 insertions(+), 30 deletions(-) diff --git a/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata index 1d526a16..919434a6 100644 --- a/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ b/example/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -2,6 +2,6 @@ + location = "self:"> diff --git a/lib/src/chips_input.dart b/lib/src/chips_input.dart index 43f5bf87..9731f4b4 100644 --- a/lib/src/chips_input.dart +++ b/lib/src/chips_input.dart @@ -449,38 +449,51 @@ class ChipsInputState extends State> ), ); - return NotificationListener( - onNotification: (SizeChangedLayoutNotification val) { - WidgetsBinding.instance?.addPostFrameCallback((_) async { - _suggestionsBoxController.overlayEntry?.markNeedsBuild(); - }); - return true; + return RawKeyboardListener( + focusNode: _focusNode, // or FocusNode() + onKey: (event) { + final str = currentTextEditingValue.text; + if (event.runtimeType.toString() == 'RawKeyDownEvent' && + event.logicalKey == LogicalKeyboardKey.backspace && + str.isNotEmpty) { + final sd = str.substring(0, str.length - 1); + updateEditingValue(TextEditingValue( + text: sd, selection: TextSelection.collapsed(offset: sd.length))); + } }, - child: SizeChangedLayoutNotifier( - child: Column( - children: [ - GestureDetector( - behavior: HitTestBehavior.opaque, - onTap: () { - requestKeyboard(); - }, - child: InputDecorator( - decoration: widget.decoration, - isFocused: _focusNode.hasFocus, - isEmpty: _value.text.isEmpty && _chips.isEmpty, - child: Wrap( - crossAxisAlignment: WrapCrossAlignment.center, - spacing: 4.0, - runSpacing: 4.0, - children: chipsChildren, + child: NotificationListener( + onNotification: (SizeChangedLayoutNotification val) { + WidgetsBinding.instance?.addPostFrameCallback((_) async { + _suggestionsBoxController.overlayEntry?.markNeedsBuild(); + }); + return true; + }, + child: SizeChangedLayoutNotifier( + child: Column( + children: [ + GestureDetector( + behavior: HitTestBehavior.opaque, + onTap: () { + requestKeyboard(); + }, + child: InputDecorator( + decoration: widget.decoration, + isFocused: _focusNode.hasFocus, + isEmpty: _value.text.isEmpty && _chips.isEmpty, + child: Wrap( + crossAxisAlignment: WrapCrossAlignment.center, + spacing: 4.0, + runSpacing: 4.0, + children: chipsChildren, + ), ), ), - ), - CompositedTransformTarget( - link: _layerLink, - child: Container(), - ), - ], + CompositedTransformTarget( + link: _layerLink, + child: Container(), + ), + ], + ), ), ), ); From 40eb1703492d5c55b37ca1907b6c34d25595e094 Mon Sep 17 00:00:00 2001 From: Jorel Cruz Date: Fri, 20 Aug 2021 11:06:45 +0800 Subject: [PATCH 2/2] - update _updateTextInputState function - remove platform specific checking in composing parameter --- lib/src/chips_input.dart | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/src/chips_input.dart b/lib/src/chips_input.dart index 9731f4b4..9d90aaa3 100644 --- a/lib/src/chips_input.dart +++ b/lib/src/chips_input.dart @@ -349,17 +349,11 @@ class ChipsInputState extends State> "${replaceText ? '' : _value.normalCharactersText}" + putText; setState(() { - final textLength = updatedText.characters.length; - final replacedLength = _chips.length; + final textLength = updatedText.length; _value = _value.copyWith( text: updatedText, selection: TextSelection.collapsed(offset: textLength), - composing: (Platform.isIOS || replacedLength == textLength) - ? TextRange.empty - : TextRange( - start: replacedLength, - end: textLength, - ), + composing: TextRange.empty, ); }); _textInputConnection ??= TextInput.attach(this, textInputConfiguration);