diff --git a/ios/Podfile b/ios/Podfile index 8623e160..2dff4172 100644 --- a/ios/Podfile +++ b/ios/Podfile @@ -42,6 +42,11 @@ post_install do |installer| project.targets.each do |target| target.build_configurations.each do |config| config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.0' + config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= [ + '$(inherited)', + ## dart: PermissionGroup.microphone + 'PERMISSION_MICROPHONE=1', + ] end end end diff --git a/lib/views/widgets/sound/record_sound.dart b/lib/views/widgets/sound/record_sound.dart index 5ca797e4..ea2be0ea 100644 --- a/lib/views/widgets/sound/record_sound.dart +++ b/lib/views/widgets/sound/record_sound.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_sound/flutter_sound.dart'; +import 'package:fluttertoast/fluttertoast.dart'; import 'package:permission_handler/permission_handler.dart'; import 'package:rive/rive.dart'; import 'package:test_sa/views/widgets/buttons/app_icon_button2.dart'; @@ -71,6 +72,8 @@ class _RecordSoundState extends State { // await Permission.camera PermissionStatus status = await Permission.microphone.request(); if (!status.isGranted) { + PermissionStatus status = await Permission.microphone.request(); + Fluttertoast.showToast(msg: "Permission Denied"); return; } _rive.addController(SimpleAnimation('recording')); @@ -114,11 +117,11 @@ class _RecordSoundState extends State { @override Widget build(BuildContext context) { return Container( - padding: EdgeInsets.only(left: 12, right: 0), + padding: const EdgeInsets.only(left: 12, right: 0), 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)), ), diff --git a/lib/views/widgets/speech_to_text/speech_to_text.dart b/lib/views/widgets/speech_to_text/speech_to_text.dart index d1e8e12c..6ceb016f 100644 --- a/lib/views/widgets/speech_to_text/speech_to_text.dart +++ b/lib/views/widgets/speech_to_text/speech_to_text.dart @@ -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 { +class SpeechToTextButtonState extends State { 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 { @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 { Widget build(BuildContext context) { _settingProvider = Provider.of(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 { setState(() {}); }, ) - : SizedBox.shrink(), - Spacer(), + : const SizedBox.shrink(), + const Spacer(), TextButton( onPressed: () { if (_speechToText.isListening) return; @@ -110,7 +113,7 @@ class _SpeechToTextButtonState extends State { 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 { Fluttertoast.showToast(msg: "microphone not available"); return; } - _startListening(); + if (_speechToText.isListening) { + _stopListening(); + } else { + _startListening(); + } }, ), ],