Closed Nico3652 closed 2 years ago
The first two will be fixed.
The third should be expected behaviour.
You may reset the content using TextEditingController
when onSubmitted
is triggered.
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
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:
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 :
Result
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 :
Thanks in advance