|
|
|
|
@ -16,13 +16,13 @@ class SpeechToTextButton extends StatefulWidget {
|
|
|
|
|
const SpeechToTextButton({Key key, this.controller, this.mini = false}) : super(key: key);
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
_SpeechToTextButtonState createState() => _SpeechToTextButtonState();
|
|
|
|
|
SpeechToTextButtonState createState() => SpeechToTextButtonState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _SpeechToTextButtonState extends State<SpeechToTextButton> {
|
|
|
|
|
class SpeechToTextButtonState extends State<SpeechToTextButton> {
|
|
|
|
|
bool _speechEnabled = false;
|
|
|
|
|
SettingProvider _settingProvider;
|
|
|
|
|
SpeechToText _speechToText = SpeechToText();
|
|
|
|
|
final SpeechToText _speechToText = SpeechToText();
|
|
|
|
|
|
|
|
|
|
/// This has to happen only once per app
|
|
|
|
|
void _initSpeech() async {
|
|
|
|
|
@ -63,12 +63,15 @@ class _SpeechToTextButtonState extends State<SpeechToTextButton> {
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
_initSpeech();
|
|
|
|
|
widget.controller.addListener(() {
|
|
|
|
|
setState(() {});
|
|
|
|
|
});
|
|
|
|
|
super.initState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void setState(VoidCallback fn) {
|
|
|
|
|
if (!this.mounted) return;
|
|
|
|
|
if (!mounted) return;
|
|
|
|
|
super.setState(fn);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -76,11 +79,11 @@ class _SpeechToTextButtonState extends State<SpeechToTextButton> {
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
_settingProvider = Provider.of<SettingProvider>(context);
|
|
|
|
|
return Container(
|
|
|
|
|
padding: EdgeInsets.only(left: 12, right: 12),
|
|
|
|
|
padding: const EdgeInsets.only(left: 12, right: 12),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: Color(0xfff5f5f5),
|
|
|
|
|
color: const Color(0xfff5f5f5),
|
|
|
|
|
border: Border.all(
|
|
|
|
|
color: Color(0xffefefef),
|
|
|
|
|
color: const Color(0xffefefef),
|
|
|
|
|
),
|
|
|
|
|
borderRadius: BorderRadius.circular(AppStyle.borderRadius * AppStyle.getScaleFactor(context)),
|
|
|
|
|
),
|
|
|
|
|
@ -95,8 +98,8 @@ class _SpeechToTextButtonState extends State<SpeechToTextButton> {
|
|
|
|
|
setState(() {});
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
|
: SizedBox.shrink(),
|
|
|
|
|
Spacer(),
|
|
|
|
|
: const SizedBox.shrink(),
|
|
|
|
|
const Spacer(),
|
|
|
|
|
TextButton(
|
|
|
|
|
onPressed: () {
|
|
|
|
|
if (_speechToText.isListening) return;
|
|
|
|
|
@ -110,7 +113,7 @@ class _SpeechToTextButtonState extends State<SpeechToTextButton> {
|
|
|
|
|
child: Text(_settingProvider.speechToText)),
|
|
|
|
|
GestureDetector(
|
|
|
|
|
child: _speechToText.isListening
|
|
|
|
|
? Icon(
|
|
|
|
|
? const Icon(
|
|
|
|
|
Icons.fiber_manual_record,
|
|
|
|
|
color: Colors.red,
|
|
|
|
|
)
|
|
|
|
|
@ -123,7 +126,11 @@ class _SpeechToTextButtonState extends State<SpeechToTextButton> {
|
|
|
|
|
Fluttertoast.showToast(msg: "microphone not available");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_startListening();
|
|
|
|
|
if (_speechToText.isListening) {
|
|
|
|
|
_stopListening();
|
|
|
|
|
} else {
|
|
|
|
|
_startListening();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
|