DEV Community

GiftMogale
GiftMogale

Posted on

textField and textEditControl ,Get user input on button click - Flutter

I am building a chat screen and trying to get messages from textEditController instead of getting them from the message model.

Code below:

 TextEditingController _controller =
  new TextEditingController();

String _text = '';

...


IconButton(
        icon: Icon(Icons.send),
        iconSize: 25.0,
        color: Theme.of(context).primaryColor,
        onPressed: () async {
          DataModel? data = await submitData(_controller);
          _dataModel = data;
          setState(
            () {
              _text = _controller.text.toString();
            },
          );
        },
      ),

....

 child: TextField(
          controller: _controller, 
          textCapitalization: TextCapitalization.sentences,
          onChanged: (value) {},
          decoration: InputDecoration(hintText: 'Send a message...'),
        ),
Enter fullscreen mode Exit fullscreen mode

Latest comments (0)