From 318560b1d7698cf48e80cde01a27b16dbec8a825 Mon Sep 17 00:00:00 2001 From: hussam al-habibeh Date: Thu, 21 Oct 2021 15:20:45 +0300 Subject: [PATCH] opertion report screen --- .../operation_report/operation_report.dart | 660 ++++++++++++++++++ .../update_operation_report.dart | 329 +++++++++ 2 files changed, 989 insertions(+) create mode 100644 lib/screens/patients/profile/operation_report/operation_report.dart create mode 100644 lib/screens/patients/profile/operation_report/update_operation_report.dart diff --git a/lib/screens/patients/profile/operation_report/operation_report.dart b/lib/screens/patients/profile/operation_report/operation_report.dart new file mode 100644 index 00000000..23f9ed28 --- /dev/null +++ b/lib/screens/patients/profile/operation_report/operation_report.dart @@ -0,0 +1,660 @@ +import 'package:doctor_app_flutter/core/model/note/note_model.dart'; +import 'package:doctor_app_flutter/core/model/note/update_note_model.dart'; +import 'package:doctor_app_flutter/core/service/AnalyticsService.dart'; +import 'package:doctor_app_flutter/core/viewModel/authentication_view_model.dart'; +import 'package:doctor_app_flutter/core/viewModel/patient_view_model.dart'; +import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart'; +import 'package:doctor_app_flutter/icons_app/doctor_app_icons.dart'; +import 'package:doctor_app_flutter/locator.dart'; +import 'package:doctor_app_flutter/models/patient/progress_note_request.dart'; +import 'package:doctor_app_flutter/screens/base/base_view.dart'; +import 'package:doctor_app_flutter/screens/patients/profile/note/update_note.dart'; +import 'package:doctor_app_flutter/util/date-utils.dart'; +import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; +import 'package:doctor_app_flutter/widgets/patients/profile/add-order/addNewOrder.dart'; +import 'package:doctor_app_flutter/widgets/patients/profile/patient-profile-app-bar.dart'; +import 'package:doctor_app_flutter/widgets/shared/card_with_bg_widget.dart'; +import 'package:doctor_app_flutter/widgets/shared/divider_with_spaces_around.dart'; +import 'package:doctor_app_flutter/widgets/shared/errors/dr_app_embedded_error.dart'; +import 'package:doctor_app_flutter/widgets/shared/loader/gif_loader_dialog_utils.dart'; +import 'package:flutter/material.dart'; +import 'package:font_awesome_flutter/font_awesome_flutter.dart'; +import 'package:provider/provider.dart'; + +import '../../../../config/shared_pref_kay.dart'; +import '../../../../models/patient/patiant_info_model.dart'; +import '../../../../util/dr_app_shared_pref.dart'; +import '../../../../widgets/shared/app_scaffold_widget.dart'; +import '../../../../widgets/shared/app_texts_widget.dart'; + +DrAppSharedPreferances sharedPref = new DrAppSharedPreferances(); + +class OperationReportScreen extends StatefulWidget { + final int visitType; + + const OperationReportScreen({Key key, this.visitType}) : super(key: key); + + @override + _ProgressNoteState createState() => _ProgressNoteState(); +} + +class _ProgressNoteState extends State { + List notesList; + var filteredNotesList; + bool isDischargedPatient = false; + AuthenticationViewModel authenticationViewModel; + ProjectViewModel projectViewModel; + + getProgressNoteList(BuildContext context, PatientViewModel model, + {bool isLocalBusy = false}) async { + final routeArgs = ModalRoute.of(context).settings.arguments as Map; + PatiantInformtion patient = routeArgs['patient']; + String token = await sharedPref.getString(TOKEN); + String type = await sharedPref.getString(SLECTED_PATIENT_TYPE); + + print(type); + ProgressNoteRequest progressNoteRequest = ProgressNoteRequest( + visitType: widget.visitType, + // if equal 5 then this will return progress note + admissionNo: int.parse(patient.admissionNo), + projectID: patient.projectId, + tokenID: token, + patientTypeID: patient.patientType, + languageID: 2); + model + .getPatientProgressNote(progressNoteRequest.toJson(), + isLocalBusy: isLocalBusy) + .then((c) { + notesList = model.patientProgressNoteList; + }); + } + + @override + Widget build(BuildContext context) { + authenticationViewModel = Provider.of(context); + projectViewModel = Provider.of(context); + final routeArgs = ModalRoute.of(context).settings.arguments as Map; + PatiantInformtion patient = routeArgs['patient']; + String arrivalType = routeArgs['arrivalType']; + if (routeArgs.containsKey('isDischargedPatient')) + isDischargedPatient = routeArgs['isDischargedPatient']; + return BaseView( + onModelReady: (model) => getProgressNoteList(context, model), + builder: (_, model, w) => AppScaffold( + baseViewModel: model, + backgroundColor: Theme.of(context).scaffoldBackgroundColor, + // appBarTitle: TranslationBase.of(context).progressNote, + appBar: PatientProfileAppBar( + patient, + isInpatient: true, + ), + body: model.patientProgressNoteList == null || + model.patientProgressNoteList.length == 0 + ? DrAppEmbeddedError( + error: TranslationBase.of(context).errorNoProgressNote) + : Container( + color: Colors.grey[200], + child: Column( + children: [ + if (!isDischargedPatient) + AddNewOrder( + onTap: () async { + await locator().logEvent( + eventCategory: "Progress Note Screen", + eventAction: "Update Progress Note", + ); + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => UpdateNoteOrder( + patientModel: model, + patient: patient, + visitType: widget.visitType, + isUpdate: false, + ), + settings: RouteSettings(name: 'UpdateNoteOrder'), + ), + ); + }, + label: widget.visitType == 3 + ? TranslationBase.of(context).addNewOrderSheet + : TranslationBase.of(context).addProgressNote, + ), + Expanded( + child: Container( + child: ListView.builder( + itemCount: model.patientProgressNoteList.length, + itemBuilder: (BuildContext ctxt, int index) { + return FractionallySizedBox( + widthFactor: 0.95, + child: CardWithBgWidget( + hasBorder: false, + bgColor: model.patientProgressNoteList[index] + .status == + 1 && + authenticationViewModel + .doctorProfile.doctorID != + model + .patientProgressNoteList[ + index] + .createdBy + ? Color(0xFFCC9B14) + : model.patientProgressNoteList[index] + .status == + 4 + ? Colors.red.shade700 + : model.patientProgressNoteList[index] + .status == + 2 + ? Colors.green[600] + : Color(0xFFCC9B14), + widget: Column( + children: [ + Column( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + if (model + .patientProgressNoteList[ + index] + .status == + 1 && + authenticationViewModel + .doctorProfile.doctorID != + model + .patientProgressNoteList[ + index] + .createdBy) + AppText( + TranslationBase.of(context) + .notePending, + fontWeight: FontWeight.bold, + color: Color(0xFFCC9B14), + fontSize: 12, + ), + if (model + .patientProgressNoteList[ + index] + .status == + 4) + AppText( + TranslationBase.of(context) + .noteCanceled, + fontWeight: FontWeight.bold, + color: Colors.red.shade700, + fontSize: 12, + ), + if (model + .patientProgressNoteList[ + index] + .status == + 2) + AppText( + TranslationBase.of(context) + .noteVerified, + fontWeight: FontWeight.bold, + color: Colors.green[600], + fontSize: 12, + ), + if (model.patientProgressNoteList[index].status != 2 && + model + .patientProgressNoteList[ + index] + .status != + 4 && + authenticationViewModel + .doctorProfile.doctorID == + model + .patientProgressNoteList[ + index] + .createdBy) + Row( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + InkWell( + onTap: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => + UpdateNoteOrder( + note: model + .patientProgressNoteList[ + index], + patientModel: + model, + patient: + patient, + visitType: widget + .visitType, + isUpdate: true, + )), + ); + }, + child: Container( + decoration: BoxDecoration( + color: Colors.grey[600], + borderRadius: + BorderRadius.circular( + 10), + ), + // color:Colors.red[600], + + child: Row( + children: [ + Icon( + DoctorApp.edit_1, + size: 12, + color: Colors.white, + ), + SizedBox( + width: 2, + ), + AppText( + TranslationBase.of( + context) + .update, + fontSize: 10, + color: Colors.white, + ), + ], + ), + padding: EdgeInsets.all(6), + ), + ), + SizedBox( + width: 10, + ), + InkWell( + onTap: () async { + showMyDialog( + context: context, + actionName: "verify", + confirmFun: () async { + GifLoaderDialogUtils + .showMyDialog( + context); + UpdateNoteReqModel + reqModel = + UpdateNoteReqModel( + admissionNo: int + .parse(patient + .admissionNo), + cancelledNote: + false, + lineItemNo: model + .patientProgressNoteList[ + index] + .lineItemNo, + createdBy: model + .patientProgressNoteList[ + index] + .createdBy, + notes: model + .patientProgressNoteList[ + index] + .notes, + verifiedNote: true, + patientTypeID: + patient + .patientType, + patientOutSA: false, + ); + await model + .updatePatientProgressNote( + reqModel); + await getProgressNoteList( + context, model, + isLocalBusy: + true); + GifLoaderDialogUtils + .hideDialog( + context); + }); + }, + child: Container( + decoration: BoxDecoration( + color: Colors.green[600], + borderRadius: + BorderRadius.circular( + 10), + ), + // color:Colors.red[600], + + child: Row( + children: [ + Icon( + FontAwesomeIcons + .check, + size: 12, + color: Colors.white, + ), + SizedBox( + width: 2, + ), + AppText( + TranslationBase.of( + context) + .noteVerify, + fontSize: 10, + color: Colors.white, + ), + ], + ), + padding: EdgeInsets.all(6), + ), + ), + SizedBox( + width: 10, + ), + InkWell( + onTap: () async { + showMyDialog( + context: context, + actionName: + TranslationBase.of( + context) + .cancel, + confirmFun: () async { + GifLoaderDialogUtils + .showMyDialog( + context, + ); + UpdateNoteReqModel + reqModel = + UpdateNoteReqModel( + admissionNo: int + .parse(patient + .admissionNo), + cancelledNote: true, + lineItemNo: model + .patientProgressNoteList[ + index] + .lineItemNo, + createdBy: model + .patientProgressNoteList[ + index] + .createdBy, + notes: model + .patientProgressNoteList[ + index] + .notes, + verifiedNote: false, + patientTypeID: + patient + .patientType, + patientOutSA: false, + ); + await model + .updatePatientProgressNote( + reqModel); + await getProgressNoteList( + context, model, + isLocalBusy: + true); + GifLoaderDialogUtils + .hideDialog( + context); + }); + }, + child: Container( + decoration: BoxDecoration( + color: Colors.red[600], + borderRadius: + BorderRadius.circular( + 10), + ), + // color:Colors.red[600], + + child: Row( + children: [ + Icon( + FontAwesomeIcons + .trash, + size: 12, + color: Colors.white, + ), + SizedBox( + width: 2, + ), + AppText( + 'Cancel', + fontSize: 10, + color: Colors.white, + ), + ], + ), + padding: EdgeInsets.all(6), + ), + ), + SizedBox( + width: 10, + ) + ], + ), + SizedBox( + height: 10, + ), + Row( + mainAxisAlignment: + MainAxisAlignment.spaceBetween, + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Container( + width: MediaQuery.of(context) + .size + .width * + 0.60, + child: Column( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + Row( + crossAxisAlignment: + CrossAxisAlignment + .start, + children: [ + AppText( + TranslationBase.of( + context) + .createdBy, + fontSize: 10, + ), + Expanded( + child: AppText( + model + .patientProgressNoteList[ + index] + .doctorName ?? + '', + fontWeight: + FontWeight.w600, + fontSize: 12, + ), + ), + ], + ), + ], + ), + ), + Column( + children: [ + AppText( + model + .patientProgressNoteList[ + index] + .createdOn != + null + ? AppDateUtils.getDayMonthYearDateFormatted( + AppDateUtils + .getDateTimeFromServerFormat(model + .patientProgressNoteList[ + index] + .createdOn), + isArabic: + projectViewModel + .isArabic, + isMonthShort: true) + : AppDateUtils + .getDayMonthYearDateFormatted( + DateTime.now(), + isArabic: + projectViewModel + .isArabic), + fontWeight: FontWeight.w600, + fontSize: 14, + ), + AppText( + model + .patientProgressNoteList[ + index] + .createdOn != + null + ? AppDateUtils.getHour( + AppDateUtils + .getDateTimeFromServerFormat(model + .patientProgressNoteList[ + index] + .createdOn)) + : AppDateUtils.getHour( + DateTime.now()), + fontWeight: FontWeight.w600, + fontSize: 14, + ), + ], + crossAxisAlignment: + CrossAxisAlignment.end, + ) + ], + ), + SizedBox( + height: 8, + ), + Row( + mainAxisAlignment: + MainAxisAlignment.start, + children: [ + Expanded( + child: AppText( + model + .patientProgressNoteList[ + index] + .notes, + fontSize: 10, + ), + ), + ]) + ], + ), + SizedBox( + height: 20, + ), + ], + ), + ), + ); + }), + ), + ), + ], + ), + ), + ), + ); + } + + showMyDialog({BuildContext context, Function confirmFun, String actionName}) { + showDialog( + context: context, + builder: (ctx) => Center( + child: Container( + width: MediaQuery.of(context).size.width * 0.8, + height: 200, + child: AppScaffold( + isShowAppBar: false, + body: Container( + color: Colors.white, + child: Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + // SizedBox(height: 20,), + SizedBox( + height: 10, + ), + Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + AppText( + TranslationBase.of(context).noteConfirm, + fontWeight: FontWeight.w600, + color: Colors.black, + fontSize: 16, + ), + ], + ), + SizedBox( + height: 10, + ), + DividerWithSpacesAround(), + SizedBox( + height: 12, + ), + + Container( + padding: EdgeInsets.all(20), + color: Colors.white, + child: AppText( + projectViewModel.isArabic + ? "هل أنت متأكد أنك تريد تنفيذ $actionName هذا الأمر؟" + : 'Are you sure you want $actionName this order?', + fontSize: 15, + textAlign: TextAlign.center, + ), + ), + + SizedBox( + height: 8, + ), + DividerWithSpacesAround(), + FractionallySizedBox( + widthFactor: 0.75, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + FlatButton( + child: AppText( + TranslationBase.of(context).cancel, + fontWeight: FontWeight.w600, + color: Colors.black, + fontSize: 16, + ), //Text("Cancel"), + onPressed: () { + Navigator.of(context).pop(); + }), + FlatButton( + child: AppText( + TranslationBase.of(context).noteConfirm, + fontWeight: FontWeight.w600, + color: Colors.red.shade700, + fontSize: 16, + ), //Text("Confirm", ), + onPressed: () async { + await confirmFun(); + Navigator.of(context).pop(); + }) + ], + ), + ) + ], + ), + ), + ), + ), + ), + )); + } +} diff --git a/lib/screens/patients/profile/operation_report/update_operation_report.dart b/lib/screens/patients/profile/operation_report/update_operation_report.dart new file mode 100644 index 00000000..768aaabf --- /dev/null +++ b/lib/screens/patients/profile/operation_report/update_operation_report.dart @@ -0,0 +1,329 @@ +import 'package:doctor_app_flutter/config/config.dart'; +import 'package:doctor_app_flutter/config/shared_pref_kay.dart'; +import 'package:doctor_app_flutter/config/size_config.dart'; +import 'package:doctor_app_flutter/core/enum/viewstate.dart'; +import 'package:doctor_app_flutter/core/model/note/CreateNoteModel.dart'; +import 'package:doctor_app_flutter/core/model/note/note_model.dart'; +import 'package:doctor_app_flutter/core/model/note/update_note_model.dart'; +import 'package:doctor_app_flutter/core/provider/robot_provider.dart'; +import 'package:doctor_app_flutter/core/viewModel/patient_view_model.dart'; +import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart'; +import 'package:doctor_app_flutter/icons_app/doctor_app_icons.dart'; +import 'package:doctor_app_flutter/models/doctor/doctor_profile_model.dart'; +import 'package:doctor_app_flutter/models/patient/patiant_info_model.dart'; +import 'package:doctor_app_flutter/models/patient/progress_note_request.dart'; +import 'package:doctor_app_flutter/screens/patients/profile/soap_update/shared_soap_widgets/bottom_sheet_title.dart'; +import 'package:doctor_app_flutter/util/dr_app_toast_msg.dart'; +import 'package:doctor_app_flutter/util/helpers.dart'; +import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; +import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart'; +import 'package:doctor_app_flutter/widgets/shared/buttons/app_buttons_widget.dart'; +import 'package:doctor_app_flutter/widgets/shared/loader/gif_loader_dialog_utils.dart'; +import 'package:doctor_app_flutter/widgets/shared/speech-text-popup.dart'; +import 'package:doctor_app_flutter/widgets/shared/text_fields/app-textfield-custom.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 UpdateOperatiomReport extends StatefulWidget { + final NoteModel note; + final PatientViewModel patientModel; + final PatiantInformtion patient; + final int visitType; + final bool isUpdate; + + const UpdateOperatiomReport( + {Key key, + this.note, + this.patientModel, + this.patient, + this.visitType, + this.isUpdate}) + : super(key: key); + + @override + _UpdateOperatiomReportState createState() => _UpdateOperatiomReportState(); +} + +class _UpdateOperatiomReportState extends State { + int selectedType; + bool isSubmitted = false; + stt.SpeechToText speech = stt.SpeechToText(); + var reconizedWord; + var event = RobotProvider(); + ProjectViewModel projectViewModel; + + TextEditingController progressNoteController = TextEditingController(); + + setSelectedType(int val) { + setState(() { + selectedType = val; + }); + } + + @override + 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); + + if (widget.note != null) { + progressNoteController.text = widget.note.notes; + } + + return AppScaffold( + isShowAppBar: false, + backgroundColor: Theme.of(context).scaffoldBackgroundColor, + body: SingleChildScrollView( + child: Container( + height: MediaQuery.of(context).size.height * 1.0, + child: Padding( + padding: EdgeInsets.all(0.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + BottomSheetTitle( + title: widget.visitType == 3 + ? (widget.isUpdate + ? TranslationBase.of(context).noteUpdate + : TranslationBase.of(context).noteAdd) + + TranslationBase.of(context).orderSheet + : (widget.isUpdate + ? TranslationBase.of(context).noteUpdate + : TranslationBase.of(context).noteAdd) + + TranslationBase.of(context).progressNote, + ), + SizedBox( + height: 10.0, + ), + Center( + child: FractionallySizedBox( + widthFactor: 0.9, + child: Column( + children: [ + Stack( + children: [ + AppTextFieldCustom( + hintText: widget.visitType == 3 + ? (widget.isUpdate + ? TranslationBase.of(context) + .noteUpdate + : TranslationBase.of(context) + .noteAdd) + + TranslationBase.of(context).orderSheet + : (widget.isUpdate + ? TranslationBase.of(context) + .noteUpdate + : TranslationBase.of(context) + .noteAdd) + + TranslationBase.of(context).progressNote, + //TranslationBase.of(context).addProgressNote, + controller: progressNoteController, + maxLines: 35, + minLines: 25, + hasBorder: true, + + // isTextFieldHasSuffix: true, + validationError: + progressNoteController.text.isEmpty && + isSubmitted + ? TranslationBase.of(context).emptyMessage + : null, + ), + Positioned( + top: + -2, //MediaQuery.of(context).size.height * 0, + right: projectViewModel.isArabic + ? MediaQuery.of(context).size.width * 0.75 + : 15, + child: Column( + children: [ + IconButton( + icon: Icon(DoctorApp.speechtotext, + color: Colors.black, size: 35), + onPressed: () { + initSpeechState() + .then((value) => {onVoiceText()}); + }, + ), + ], + )) + ], + ), + ], + ), + ), + ), + ], + ), + ), + ), + ), + bottomSheet: Container( + height: progressNoteController.text.isNotEmpty ? 130 : 70, + margin: EdgeInsets.all(SizeConfig.widthMultiplier * 5), + child: Column( + children: [ + if (progressNoteController.text.isNotEmpty) + Container( + margin: EdgeInsets.all(5), + child: AppButton( + title: TranslationBase.of(context).clearText, + onPressed: () { + setState(() { + progressNoteController.text = ''; + }); + }, + ), + ), + Container( + margin: EdgeInsets.all(5), + child: AppButton( + title: widget.visitType == 3 + ? (widget.isUpdate + ? TranslationBase.of(context).noteUpdate + : TranslationBase.of(context).noteAdd) + + TranslationBase.of(context).orderSheet + : (widget.isUpdate + ? TranslationBase.of(context).noteUpdate + : TranslationBase.of(context).noteAdd) + + TranslationBase.of(context).progressNote, + color: Color(0xff359846), + // disabled: progressNoteController.text.isEmpty, + fontWeight: FontWeight.w700, + onPressed: () async { + setState(() { + isSubmitted = true; + }); + if (progressNoteController.text.trim().isNotEmpty) { + GifLoaderDialogUtils.showMyDialog(context); + Map profile = await sharedPref.getObj(DOCTOR_PROFILE); + + DoctorProfileModel doctorProfile = + DoctorProfileModel.fromJson(profile); + + if (widget.isUpdate) { + UpdateNoteReqModel reqModel = UpdateNoteReqModel( + admissionNo: int.parse(widget.patient.admissionNo), + cancelledNote: false, + lineItemNo: widget.note.lineItemNo, + createdBy: widget.note.createdBy, + notes: progressNoteController.text, + verifiedNote: false, + patientTypeID: widget.patient.patientType, + patientOutSA: false, + ); + await widget.patientModel + .updatePatientProgressNote(reqModel); + } else { + CreateNoteModel reqModel = CreateNoteModel( + admissionNo: + int.parse(widget.patient.admissionNo), + createdBy: doctorProfile.doctorID, + visitType: widget.visitType, + patientID: widget.patient.patientId, + nursingRemarks: ' ', + patientTypeID: widget.patient.patientType, + patientOutSA: false, + notes: progressNoteController.text); + + await widget.patientModel + .createPatientProgressNote(reqModel); + } + + if (widget.patientModel.state == ViewState.ErrorLocal) { + Helpers.showErrorToast(widget.patientModel.error); + } else { + ProgressNoteRequest progressNoteRequest = + ProgressNoteRequest( + visitType: widget.visitType, + // if equal 5 then this will return progress note + admissionNo: + int.parse(widget.patient.admissionNo), + projectID: widget.patient.projectId, + patientTypeID: widget.patient.patientType, + languageID: 2); + await widget.patientModel.getPatientProgressNote( + progressNoteRequest.toJson()); + } + GifLoaderDialogUtils.hideDialog(context); + DrAppToastMsg.showSuccesToast( + "Your Order added Successfully"); + Navigator.of(context).pop(); + } else { + Helpers.showErrorToast("You cant add only spaces"); + } + })), + ], + ), + ), + ); + } + + 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 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(); + progressNoteController.text += reconizedWord + '\n'; + }); + } else { + print(result.finalResult); + } + } + + Future initSpeechState() async { + bool hasSpeech = await speech.initialize( + onError: errorListener, onStatus: statusListener); + print(hasSpeech); + if (!mounted) return; + } +}