I am using TextFormField to display the dynamic text. I am also using 'speech_to_text' plugin to convert the speech into text. Then the converted text is set in the TextFormField which is scrollable.
When i write in the TextformField its scrolling to bottom if the text overflows. But its not auto scrolling when setting the text from using dynamic variable like below;
SingleChildScrollView(
controller: _scrollController2,
child: Container(
width: double.infinity,
height: 50,
margin: const EdgeInsets.only(top: 5),
decoration: BoxDecoration(
color: AppColors.white,
borderRadius: BorderRadius.circular(0),
),
child: TextFormField(
enabled: true,
controller: _textFromSpeechController2,
onChanged: (value) {
setState(() {
_scrollController2.animateTo(_scrollController2.position.maxScrollExtent,
duration: Duration(microseconds: 200),
curve:Curves.easeInOut );
});
},
maxLines: null,
expands: true,
keyboardType: TextInputType.multiline,
decoration: const InputDecoration(
border: InputBorder.none,
contentPadding: EdgeInsets.symmetric(
horizontal: 5, vertical: 5),
),
textInputAction: TextInputAction.done,
),
),
),
speech_to_text
late stt.SpeechToText _speech;
String _speechText = '';
String newText = "";
Future<void> _listenForSpeech() async {
// print("_listenForSpeech called ");
if (isAvailable) {
print("isAvailable 11 " + isAvailable.toString());
bool isListening = await _speech.listen(
onResult: (result) {
setState(() {
_isListening = true;
newText = result.recognizedWords;
_textFromSpeechController2.text = result.recognizedWords;
// print("newText --- " + newText);
});
},
);
if (!isListening) {
setState(() {
_speechText = 'Failed to start listening';
});
}
} else {
setState(() {
_speechText = 'Speech recognition not available';
print("not supported");
});
}
}
The speech_to_text is working fine and setting the text into the TextFormField. But the problem is that its not scrolling to the bottom automatically when the text is overflows.