livecare changes
parent
ced177e1c0
commit
0ed0dbb5aa
@ -0,0 +1,108 @@
|
|||||||
|
import 'dart:html';
|
||||||
|
|
||||||
|
import 'package:doctor_app_flutter/config/config.dart';
|
||||||
|
import 'package:doctor_app_flutter/core/provider/robot_provider.dart';
|
||||||
|
import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart';
|
||||||
|
import 'package:doctor_app_flutter/models/patient/patiant_info_model.dart';
|
||||||
|
import 'package:doctor_app_flutter/util/translations_delegate_base.dart';
|
||||||
|
import 'package:doctor_app_flutter/widgets/shared/speech-text-popup.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:speech_to_text/speech_recognition_error.dart';
|
||||||
|
import 'package:speech_to_text/speech_to_text.dart' as stt;
|
||||||
|
|
||||||
|
class LivaCareTransferToAdmin extends StatefulWidget {
|
||||||
|
|
||||||
|
final PatiantInformtion patient;
|
||||||
|
|
||||||
|
const LivaCareTransferToAdmin({Key key, this.patient}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
_LivaCareTransferToAdminState createState() => _LivaCareTransferToAdminState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _LivaCareTransferToAdminState extends State<LivaCareTransferToAdmin> {
|
||||||
|
|
||||||
|
stt.SpeechToText speech = stt.SpeechToText();
|
||||||
|
var reconizedWord;
|
||||||
|
var event = RobotProvider();
|
||||||
|
ProjectViewModel projectViewModel;
|
||||||
|
|
||||||
|
TextEditingController noteController = TextEditingController();
|
||||||
|
|
||||||
|
void initState() {
|
||||||
|
requestPermissions();
|
||||||
|
event.controller.stream.listen((p) {
|
||||||
|
if (p['startPopUp'] == 'true') {
|
||||||
|
if (this.mounted) {
|
||||||
|
initSpeechState().then((value) => {onVoiceText()});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
projectViewModel = Provider.of(context);
|
||||||
|
|
||||||
|
return Container(
|
||||||
|
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
onVoiceText() async {
|
||||||
|
new SpeechToText(context: context).showAlertDialog(context);
|
||||||
|
var lang = TranslationBase.of(AppGlobal.CONTEX).locale.languageCode;
|
||||||
|
bool available = await speech.initialize(
|
||||||
|
onStatus: statusListener, onError: errorListener);
|
||||||
|
if (available) {
|
||||||
|
speech.listen(
|
||||||
|
onResult: resultListener,
|
||||||
|
listenMode: stt.ListenMode.confirmation,
|
||||||
|
localeId: lang == 'en' ? 'en-US' : 'ar-SA',
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
print("The user has denied the use of speech recognition.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void errorListener(SpeechRecognitionError error) {
|
||||||
|
event.setValue({"searchText": 'null'});
|
||||||
|
//SpeechToText.closeAlertDialog(context);
|
||||||
|
print(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
void statusListener(String status) {
|
||||||
|
reconizedWord = status == 'listening' ? 'Lisening...' : 'Sorry....';
|
||||||
|
}
|
||||||
|
|
||||||
|
void requestPermissions() async {
|
||||||
|
Map<Permission, PermissionStatus> statuses = await [
|
||||||
|
Permission.microphone,
|
||||||
|
].request();
|
||||||
|
}
|
||||||
|
|
||||||
|
void resultListener(result) {
|
||||||
|
reconizedWord = result.recognizedWords;
|
||||||
|
event.setValue({"searchText": reconizedWord});
|
||||||
|
|
||||||
|
if (result.finalResult == true) {
|
||||||
|
setState(() {
|
||||||
|
SpeechToText.closeAlertDialog(context);
|
||||||
|
speech.stop();
|
||||||
|
noteController.text += reconizedWord + '\n';
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
print(result.finalResult);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> initSpeechState() async {
|
||||||
|
bool hasSpeech = await speech.initialize(
|
||||||
|
onError: errorListener, onStatus: statusListener);
|
||||||
|
print(hasSpeech);
|
||||||
|
if (!mounted) return;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue