Skip to content

Commit

Permalink
- update Chips_input.dart
Browse files Browse the repository at this point in the history
   - Wrapped notificationListener with RawKeyboardListener to fix bug for android devices
  • Loading branch information
Jorel Cruz committed Aug 19, 2021
1 parent f674f1c commit 62d5e1d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 30 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

71 changes: 42 additions & 29 deletions lib/src/chips_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -449,38 +449,51 @@ class ChipsInputState<T> extends State<ChipsInput<T>>
),
);

return NotificationListener<SizeChangedLayoutNotification>(
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: <Widget>[
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<SizeChangedLayoutNotification>(
onNotification: (SizeChangedLayoutNotification val) {
WidgetsBinding.instance?.addPostFrameCallback((_) async {
_suggestionsBoxController.overlayEntry?.markNeedsBuild();
});
return true;
},
child: SizeChangedLayoutNotifier(
child: Column(
children: <Widget>[
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(),
),
],
),
),
),
);
Expand Down

0 comments on commit 62d5e1d

Please sign in to comment.