【发布时间】:2021-09-13 22:26:05
【问题描述】:
我在让 this package 处理我的项目时遇到问题。按照他们文档中给出的示例,我能够得到我认为可以正常工作的内容,但是在模拟器上启动应用程序时,它会崩溃并出现以下错误:
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
);
}
}
到目前为止我已经尝试过:
- 更新颤振
- 扑干净
- 扑医生(一切都好)
- 从 vs 代码和终端启动
这些尝试的解决方案没有运气,非常感谢任何帮助。
【问题讨论】:
-
尝试清理 pub 缓存,检查this answer
-
不走运 :( 可能是版本问题?
-
能否请您提供最小可重复的样本
标签: flutter