Flutter - How to dismiss the keyboard and add the text from the textfield to the screen and update the screen. Not able to do both simultaneously

Viewed 94

Here is my code:

bottomNavigationBar: MessageSendButton(
                        messageController: _controller,
                        onPressed: (){
                          messageList.value = []..addAll(messageList.value)..add(
                            MessageModel(
                              id: 1,
                              message: _controller.text,
                              firstName: data.firstName,
                              lastName: data.lastName,
                              createdAt: "2019-04-12 14:22:57.358854000",
                            ),
                          );
                        
                          _controller.text = '';
                          _scrollController.position.maxScrollExtent;
                          // 
                        }
                      ),

I tried using FocusScope.of(context).unfocus();, SystemChannels.textInput.invokeMethod('TextInput.hide'); and

if (!currentFocus.hasPrimaryFocus && currentFocus.focusedChild != null) {
                            FocusManager.instance.primaryFocus!.unfocus();
                          }

But its not working in the sense that it removes the keyboard but I am not able to add to my existing SliverList and rebuild the screen. If I remove the code for dismissing the keypad, I can successfully add to my existing list and rebuild the screen.

The only info I am getting is /TextInputPlugin(19317): Changing the content within the the composing region may cause the input method to behave strangely, and is therefore discouraged. See https://github.com/flutter/flutter/issues/78827 for more details I went to that link but wasn't able to infer much.

P.S. I am also not able to scroll to the bottom with my scrollController, _scrollController.position.maxScrollExtent; It just doesn't works.

0 Answers
Related