Skip to content

Commit

Permalink
fix: backspace of initial values is working
Browse files Browse the repository at this point in the history
Uses the fix described in a comment on issue #115 in the danvick repo.
danvick/flutter_chips_input#115

flutter test passes
  • Loading branch information
nlfiedler committed Mar 15, 2023
1 parent 6167650 commit e90ee8b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
7 changes: 5 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Chips Input',
title: 'Flutter ChipsInput',
theme: ThemeData(
primarySwatch: Colors.blue,
),
Expand Down Expand Up @@ -43,7 +43,7 @@ class MyHomePageState extends State<MyHomePage> {
];

return Scaffold(
appBar: AppBar(title: const Text('Flutter ChipsInput Example')),
appBar: AppBar(title: const Text('Flutter ChipsInput')),
body: Padding(
padding: const EdgeInsets.all(20),
child: SingleChildScrollView(
Expand All @@ -55,6 +55,9 @@ class MyHomePageState extends State<MyHomePage> {
),
ChipsInput(
key: _chipKey,
initialValue: const [
AppProfile('John', 'john@flutter.io', 'man-3.png')
],
textStyle: const TextStyle(
height: 1.5,
fontFamily: 'Roboto',
Expand Down
5 changes: 1 addition & 4 deletions lib/src/chips_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,10 @@ class ChipsInputState<T> extends State<ChipsInput<T>> with TextInputClient {
?.where((r) => !_chips.contains(r))
.toList(growable: false);
_suggestionsBoxController = SuggestionsBoxController(context);

_effectiveFocusNode.addListener(_handleFocusChanged);
_nodeAttachment = _effectiveFocusNode.attach(context);
_effectiveFocusNode.canRequestFocus = _canRequestFocus;

_updateTextInputState(replaceText: true);
WidgetsBinding.instance.addPostFrameCallback((_) async {
_initOverlayEntry();
if (mounted && widget.autofocus) {
Expand Down Expand Up @@ -377,7 +376,6 @@ class ChipsInputState<T> extends State<ChipsInput<T>> with TextInputClient {
));
}
if (!kIsWeb) {
// hack for https://github.com/danvick/flutter_chips_input/issues/34
_closeInputConnectionIfNeeded();
}
_textInputConnection ??= TextInput.attach(this, textInputConfiguration);
Expand Down Expand Up @@ -478,7 +476,6 @@ class ChipsInputState<T> extends State<ChipsInput<T>> with TextInputClient {
if (event.runtimeType.toString() == 'RawKeyDownEvent' &&
event.logicalKey == LogicalKeyboardKey.backspace &&
str.isNotEmpty) {
// TODO: try just str.length here
final sd = str.substring(0, str.length - 1);
updateEditingValue(TextEditingValue(
text: sd, selection: TextSelection.collapsed(offset: sd.length)));
Expand Down

0 comments on commit e90ee8b

Please sign in to comment.