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

[BUG] Placer Holder value submitted #15

Closed
Nico3652 opened this issue Dec 3, 2021 · 3 comments · Fixed by #17
Closed

[BUG] Placer Holder value submitted #15

Nico3652 opened this issue Dec 3, 2021 · 3 comments · Fixed by #17

Comments

@Nico3652
Copy link

Nico3652 commented Dec 3, 2021

First problem, when I'm closing the keyboard by touching outside the onSubmitted callback is fired and don't know why.

Second, when the field is empty, my place holder value is submitted :

placeholder: 'message',
onSubmitted: (String? value) {
  print("submitted value : $value");
},

Result

flutter: submitted value : message

Third, when I'm submitted the textfield config is not reset :
ex : If I wrote 3 lines and submit the place holder is not printed again and the 3 lines config is remaining :

Capture d’écran 2021-12-03 à 14 44 44

Thanks in advance

@henryleunghk
Copy link
Owner

The first two will be fixed.

The third should be expected behaviour.
You may reset the content using TextEditingController when onSubmitted is triggered.

@Nico3652
Copy link
Author

Nico3652 commented Dec 4, 2021

Thanks for improvement.
Indeed for the controller, but it was already what I used :

NativeTextInput(
      returnKeyType: ReturnKeyType.send,
      cursorColor: ThemeProvider.colorApp1,
      textCapitalization: TextCapitalization.sentences,
      style: Theme.of(context).textTheme.bodyText1,
      decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(chatHeight / 2),
          border: Border.all(color: chatColor, width: 0.8)),
      placeholderStyle: ThemeProvider.instance.getPlacerHolderStyle(),
      placeholder: 'message',
      onSubmitted: (String? value) {
        print("submitted value : $value");
        if (value != null && value.trim().isNotEmpty) {
          sendNewMessage(value.trim());
          messagesViewModel.saveTyping(typing: false);
        }
      },
      keyboardAppearance: Theme.of(context).brightness,
      focusNode: focusNode,
      minLines: 1,
      maxLines: 3,
      onChanged: (value) {
        if (value.isNotEmpty) {
          messagesViewModel.saveTyping(typing: true);
        } else if (value.isEmpty) {
          messagesViewModel.saveTyping(typing: false);
        }
      },
      controller: textEditingController,
    );

And within the sendMessage() :

void sendNewMessage(String content) {
    textEditingController.clear();
    print('text controller clear the field ');
    emptyChat.value = true;
    messagesViewModel.sendTextMessage(content);
    messagesViewModel.saveTyping(typing: false);
    //FocusScope.of(context).requestFocus(focusNode);
    focusNode.requestFocus();
  }

The textfield lines (in the picture above) is still not reset after the textEditingController.clear() whereas the placeholder is reset

@henryleunghk
Copy link
Owner

Try this:

NativeTextInput(
  controller: _changeTextController,
  focusNode: _focusNode,
  placeholder: 'placeholder',
  onSubmitted: _onSubmittedText,
)
_onSubmittedText(value) {
  _changeTextController.clear();
  FocusScope.of(context).requestFocus(_focusNode);
}

This is working fine to me:

Screen.Recording.2021-12-05.at.15.11.19.mov

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 a pull request may close this issue.

2 participants