我很难让这个包裹在我的项目上工作。按照他们的文档中给出的示例,我能够找到我认为是功能性的东西,但在模拟器上启动应用程序时,它会崩溃,并出现以下错误:
Error handling 'checkPlatformOverride' custom request: method not available: ext.flutter.platformOverride
Error handling 'checkBrightnessOverride' custom request: method not available: ext.flutter.brightnessOverride
Error handling 'serviceExtension' custom request: method not available: ext.flutter.inspector.setPubRootDirectories
Error handling 'checkIsWidgetCreationTracked' custom request: method not available: ext.flutter.inspector.isWidgetCreationTracked下面是实现包的主要代码块:
import 'package:flutter/material.dart';
import 'package:speech_to_text/speech_to_text.dart';
import 'package:speech_to_text/speech_recognition_result.dart';
class CustomNav extends StatefulWidget {
List<Widget> screens;
int currentScreensIndex;
Function(int) onScreenChange;
//list of screens and the starting index (initial _currentScreensIndex)
CustomNav({
required this.screens,
required this.currentScreensIndex,
required this.onScreenChange,
});
@override
_CustomNavState createState() => _CustomNavState();
}
class _CustomNavState extends State<CustomNav> {
SpeechToText _speechToText = SpeechToText();
bool _speechEnabled = false;
String _lastWords = "";
//this is called once the speech button is pressed
activateStt() async {
await _speechToText.listen(onResult: _onSpeechResult);
setState(() {});
}
void _onSpeechResult(SpeechRecognitionResult result) {
setState(() {
_lastWords = result.recognizedWords;
});
}
@override
void initState() {
super.initState();
_initSpeech();
}
void _initSpeech() async {
_speechEnabled = await _speechToText.initialize();
setState(() {});
}
@override
Widget build(BuildContext context) {
double width = MediaQuery.of(context).size.width;
return Container(
color: Colors.white,
width: width,
height: 100,
//row of buttons
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
//onScreenChange method calls is where the logic takes place
IconButton(
onPressed: () {
widget.onScreenChange(0);
},
icon: Icon(Icons.home_outlined)),
ElevatedButton(
style: ElevatedButton.styleFrom(
primary: Theme.of(context).accentColor,
minimumSize: Size(60, 60),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(25.0)),
elevation: 4,
shadowColor: Theme.of(context).accentColor),
onPressed: () {
//activate a method that record audio then converts it to text.
activateStt();
},
child: Icon(Icons.mic, color: Colors.white)),
IconButton(
onPressed: () {
widget.onScreenChange(2);
},
icon: Icon(Icons.view_sidebar))
],
),
//could add spacing here
);
}
}到目前为止,我已经尝试过:
没有这些尝试的解决方案,任何帮助都是非常感谢的。
发布于 2021-09-22 13:27:15
检查是否是插件版本的问题。
speech_to_text: anyhttps://stackoverflow.com/questions/69169741
复制相似问题