Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix backspace bug for android devices #96

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jorelkimcruz
Copy link

  • Wrapped notificationListener with RawKeyboardListener to fix bug for android devices

   - Wrapped notificationListener with RawKeyboardListener to fix bug for android devices
@jorelkimcruz
Copy link
Author

jorelkimcruz commented Aug 19, 2021

also in my case I also have to revert to

  void _updateTextInputState({bool replaceText = false, String putText = ''}) {
    if (replaceText || putText != '') {
      final updatedText =
          String.fromCharCodes(_chips.map((_) => kObjectReplacementChar)) +
              (replaceText ? '' : _value.normalCharactersText) +
              putText;
      setState(() => _value = _value.copyWith(
            text: updatedText,
            selection: TextSelection.collapsed(offset: updatedText.length),
            //composing: TextRange(start: 0, end: text.length),
            composing: TextRange.empty,
          ));
    }
    _closeInputConnectionIfNeeded(); //Hack for #34 (https://github.com/danvick/flutter_chips_input/issues/34#issuecomment-684505282). TODO: Find permanent fix
    _textInputConnection ??= TextInput.attach(this, textInputConfiguration);
    _textInputConnection?.setEditingState(_value);
  }

but this is not in the PR.

@jorelkimcruz jorelkimcruz force-pushed the fix_backspace_not_working_for_android_devices branch from 7d73d1c to 2193b3a Compare August 20, 2021 03:04
@jorelkimcruz
Copy link
Author

@jorelkimcruz Hey, I have tested your changes but found some bug while testing on 'Samsung Phone'. These changes have fixed errors in the case of the alphabet but in the case of numbers, the problem persists.

Updated PR

this is what causing the issue.

 composing: (Platform.isIOS || replacedLength == textLength)
            ? TextRange.empty
            : TextRange(
                start: replacedLength,
                end: textLength,
              ),
  void _updateTextInputState({bool replaceText = false, String putText = ''}) {
    if (replaceText || putText != '') {
      final updatedText =
          String.fromCharCodes(_chips.map((_) => kObjectReplacementChar)) +
              (replaceText ? '' : _value.normalCharactersText) +
              putText;
      setState(() => _value = _value.copyWith(
            text: updatedText,
            selection: TextSelection.collapsed(offset: updatedText.length),
            //composing: TextRange(start: 0, end: text.length),
            composing: TextRange.empty,
          ));
    }
    _closeInputConnectionIfNeeded(); //Hack for #34 (https://github.com/danvick/flutter_chips_input/issues/34#issuecomment-684505282). TODO: Find permanent fix
    _textInputConnection ??= TextInput.attach(this, textInputConfiguration);
    _textInputConnection?.setEditingState(_value);
  }

@jorelkimcruz jorelkimcruz force-pushed the fix_backspace_not_working_for_android_devices branch from 2193b3a to e73db32 Compare August 20, 2021 03:06
	- remove platform specific checking in composing parameter
@jorelkimcruz jorelkimcruz force-pushed the fix_backspace_not_working_for_android_devices branch from e73db32 to 40eb170 Compare August 20, 2021 03:07
@aman-singh7
Copy link

@jorelkimcruz Hey, the above commits have fixed the issue but the cursor is not visible. can you fix this?

@jorelkimcruz
Copy link
Author

@jorelkimcruz Hey, the above commits have fixed the issue but the cursor is not visible. can you fix this?

have you tried changing the cursors color?

@aman-singh7
Copy link

@jorelkimcruz Hey, the above commits have fixed the issue but the cursor is not visible. can you fix this?

have you tried changing the cursors color?

Is there a way to change the cursor color? I am not able to find any parameter that does this.

@jorelkimcruz
Copy link
Author

jorelkimcruz commented Aug 21, 2021

@jorelkimcruz Hey, the above commits have fixed the issue but the cursor is not visible. can you fix this?

have you tried changing the cursors color?

Is there a way to change the cursor color? I am not able to find any parameter that does this.

inside text_cursor.dart

@brianlenz
Copy link

@jorelkimcruz, have you tried this on the iOS simulator? I just tried out your branch (per #97 (comment)), and it seems to fix the focus issue, but it has a really strange issue of character repeating. When you type (with a hardware keyboard) into the input in the iOS simulator, sometimes a key that you hit once may be repeated multiple times. I've noticed this both for entering new letters as well as backspacing (where sometimes a single backspace will remove multiple characters).

@jorelkimcruz
Copy link
Author

jorelkimcruz commented Oct 13, 2021

@jorelkimcruz, have you tried this on the iOS simulator? I just tried out your branch (per #97 (comment)), and it seems to fix the focus issue, but it has a really strange issue of character repeating. When you type (with a hardware keyboard) into the input in the iOS simulator, sometimes a key that you hit once may be repeated multiple times. I've noticed this both for entering new letters as well as backspacing (where sometimes a single backspace will remove multiple characters).

Hi, Sorry been busy and didnt got the time to push a fix. but if you need this asap here is a fix.
you might want to update

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);
          updateEditingValue(TextEditingValue(
              text: sd, selection: TextSelection.collapsed(offset: sd.length)));
        }
      },
      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(),
              ),
            ],
          ),
        ),
      ),
    );

@brianlenz
Copy link

@jorelkimcruz, we're not actively using your branch, so no rush on a fix. The main issue we were trying to work around is with the iOS keyboard disappearing, which I have submitted #99 for.

I'll be happy to test out your change again once you push the change onto your branch, too 👍

ChillkroeteTTS pushed a commit to ChillkroeteTTS/flutter_chips_input that referenced this pull request Jan 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants