【发布时间】:2019-10-26 17:42:54
【问题描述】:
我在文本字段中添加了语音识别,它可以工作,但我无法将文本添加到文本字段,有没有办法做到这一点。
文本字段如下所示:
Widget _buildDescriptionTextField(productBloc) {
return StreamBuilder<Object>(
stream: productBloc.messageStream,
builder: (context, snapshot) {
return TextField(
maxLines: 3,
controller: _controllerMessage,
onChanged: productBloc.messageSink,
decoration: InputDecoration(
labelText: allTranslations.text(StringConstant.description),
errorText: snapshot.error,
suffixIcon: IconButton(icon: Icon(Icons.mic), onPressed: () {
if (_isAvailable && !_isListening)
_speechRecognition
.listen(locale: "en_US")
.then((result) => print('$result'));
},
),
),
);
}
);
}
我有一个 steam-builder 来手动管理添加的文本,如果此页面用于编辑,我有一个控制器,然后作为 suffixsIcon 的 iconButton 启动语音识别。当我在文本小部件之外添加结果文本时,它可以工作,但我需要在 texField 中使用它。
【问题讨论】:
标签: flutter speech-recognition textfield flutter-layout