You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
306 lines
13 KiB
Dart
306 lines
13 KiB
Dart
import 'package:doctor_app_flutter/config/config.dart';
|
|
import 'package:doctor_app_flutter/core/enum/viewstate.dart';
|
|
import 'package:doctor_app_flutter/core/model/referral/MyReferralPatientModel.dart';
|
|
import 'package:doctor_app_flutter/core/model/referral/add_referred_remarks_request.dart';
|
|
import 'package:doctor_app_flutter/core/provider/robot_provider.dart';
|
|
import 'package:doctor_app_flutter/core/viewModel/patient-referral-viewmodel.dart';
|
|
import 'package:doctor_app_flutter/icons_app/doctor_app_icons.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:speech_to_text/speech_recognition_error.dart';
|
|
import 'package:speech_to_text/speech_to_text.dart' as stt;
|
|
|
|
import 'ReplySummeryOnReferralPatient.dart';
|
|
|
|
class AddReplayOnReferralPatient extends StatefulWidget {
|
|
final PatientReferralViewModel patientReferralViewModel;
|
|
final MyReferralPatientModel myReferralInPatientModel;
|
|
final AddReferredRemarksRequestModel myReferralInPatientRequestModel;
|
|
final bool isEdited;
|
|
|
|
const AddReplayOnReferralPatient(
|
|
{Key key,
|
|
this.patientReferralViewModel,
|
|
this.myReferralInPatientModel,
|
|
this.isEdited,
|
|
this.myReferralInPatientRequestModel})
|
|
: super(key: key);
|
|
|
|
@override
|
|
_AddReplayOnReferralPatientState createState() => _AddReplayOnReferralPatientState();
|
|
}
|
|
|
|
class _AddReplayOnReferralPatientState extends State<AddReplayOnReferralPatient> {
|
|
bool isSubmitted = false;
|
|
int replay = 1;
|
|
int reject = 2;
|
|
stt.SpeechToText speech = stt.SpeechToText();
|
|
var reconizedWord;
|
|
var event = RobotProvider();
|
|
TextEditingController replayOnReferralController = TextEditingController();
|
|
|
|
@override
|
|
void initState() {
|
|
requestPermissions();
|
|
super.initState();
|
|
replayOnReferralController.text = widget.myReferralInPatientModel.referredDoctorRemarks ?? "";
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return AppScaffold(
|
|
isShowAppBar: false,
|
|
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
|
|
body: Column(
|
|
children: [
|
|
Expanded(
|
|
child: SingleChildScrollView(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
BottomSheetTitle(title: 'Reply'),
|
|
SizedBox(
|
|
height: 10.0,
|
|
),
|
|
Center(
|
|
child: FractionallySizedBox(
|
|
widthFactor: 0.9,
|
|
child: Column(
|
|
children: [
|
|
Stack(
|
|
children: [
|
|
AppTextFieldCustom(
|
|
hintText: 'Reply your responses here',
|
|
controller: replayOnReferralController,
|
|
maxLines: 35,
|
|
minLines: 25,
|
|
hasBorder: true,
|
|
validationError: replayOnReferralController.text.isEmpty && isSubmitted
|
|
? TranslationBase.of(context).emptyMessage
|
|
: null,
|
|
),
|
|
Positioned(
|
|
top: 0,
|
|
//MediaQuery.of(context).size.height * 0,
|
|
right: 15,
|
|
child: IconButton(
|
|
icon: Icon(
|
|
DoctorApp.speechtotext,
|
|
color: Colors.black,
|
|
size: 35,
|
|
),
|
|
onPressed: () {
|
|
onVoiceText();
|
|
},
|
|
),
|
|
)
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
Container(
|
|
// height: replayOnReferralController.text.isNotEmpty ? 130 : 70,
|
|
// margin: EdgeInsets.all(SizeConfig.widthMultiplier * 5),
|
|
child: Column(
|
|
children: <Widget>[
|
|
replayOnReferralController.text.isEmpty
|
|
? SizedBox()
|
|
: Container(
|
|
margin: EdgeInsets.all(16),
|
|
child: AppButton(
|
|
title: TranslationBase.of(context).clearText,
|
|
onPressed: () {
|
|
setState(() {
|
|
replayOnReferralController.text = '';
|
|
});
|
|
},
|
|
),
|
|
),
|
|
Container(
|
|
margin: EdgeInsets.fromLTRB(16, 0, 16, 16),
|
|
child: Row(
|
|
children: [
|
|
Expanded(
|
|
child: AppButton(
|
|
onPressed: () async {
|
|
if (replayOnReferralController.text.isNotEmpty) {
|
|
GifLoaderDialogUtils.showMyDialog(context);
|
|
await widget.patientReferralViewModel.replayReferred(
|
|
replayOnReferralController.text.trim(), widget.myReferralInPatientModel, reject);
|
|
if (widget.patientReferralViewModel.state == ViewState.ErrorLocal) {
|
|
Helpers.showErrorToast(widget.patientReferralViewModel.error);
|
|
} else {
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
DrAppToastMsg.showSuccesToast("Has been rejected");
|
|
Navigator.of(context).pop();
|
|
Navigator.of(context).pop();
|
|
|
|
// Navigator.push(
|
|
// context,
|
|
// FadePage(
|
|
// page: ReplySummeryOnReferralPatient(
|
|
// widget.myReferralInPatientModel, replayOnReferralController.text.trim()),
|
|
// ),
|
|
// );
|
|
}
|
|
} else {
|
|
Helpers.showErrorToast("You can't add empty reply");
|
|
setState(() {
|
|
isSubmitted = false;
|
|
});
|
|
}
|
|
},
|
|
title: TranslationBase.of(context).reject,
|
|
fontColor: Colors.white,
|
|
color: Colors.red[600],
|
|
),
|
|
),
|
|
SizedBox(
|
|
width: 4,
|
|
),
|
|
Expanded(
|
|
child: AppButton(
|
|
onPressed: () async {
|
|
setState(() {
|
|
isSubmitted = true;
|
|
});
|
|
if (replayOnReferralController.text.isNotEmpty) {
|
|
GifLoaderDialogUtils.showMyDialog(context);
|
|
await widget.patientReferralViewModel.replayReferred(
|
|
replayOnReferralController.text.trim(), widget.myReferralInPatientModel, replay);
|
|
if (widget.patientReferralViewModel.state == ViewState.ErrorLocal) {
|
|
Helpers.showErrorToast(widget.patientReferralViewModel.error);
|
|
} else {
|
|
GifLoaderDialogUtils.hideDialog(context);
|
|
DrAppToastMsg.showSuccesToast("Your Reply Added Successfully");
|
|
Navigator.of(context).pop();
|
|
Navigator.of(context).pop();
|
|
|
|
// Navigator.push(
|
|
// context,
|
|
// FadePage(
|
|
// page: ReplySummeryOnReferralPatient(
|
|
// widget.myReferralInPatientModel, replayOnReferralController.text.trim()),
|
|
// ),
|
|
// );
|
|
}
|
|
} else {
|
|
Helpers.showErrorToast("You can't add empty reply");
|
|
setState(() {
|
|
isSubmitted = false;
|
|
});
|
|
}
|
|
},
|
|
title: TranslationBase.of(context).noteConfirm,
|
|
fontColor: Colors.white,
|
|
color: Colors.green[600],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
// Container(
|
|
// margin: EdgeInsets.all(5),
|
|
// child: AppButton(
|
|
// title: 'Submit Reply',
|
|
// color: Color(0xff359846),
|
|
// fontWeight: FontWeight.w700,
|
|
// onPressed: () async {
|
|
// setState(() {
|
|
// isSubmitted = true;
|
|
// });
|
|
// if (replayOnReferralController.text.isNotEmpty) {
|
|
// GifLoaderDialogUtils.showMyDialog(context);
|
|
// await widget.patientReferralViewModel.replay(
|
|
// replayOnReferralController.text.trim(),
|
|
// widget.myReferralInPatientModel);
|
|
// if (widget.patientReferralViewModel.state ==
|
|
// ViewState.ErrorLocal) {
|
|
// Helpers.showErrorToast(
|
|
// widget.patientReferralViewModel.error);
|
|
// } else {
|
|
// GifLoaderDialogUtils.hideDialog(context);
|
|
// DrAppToastMsg.showSuccesToast(
|
|
// "Your Reply Added Successfully");
|
|
// Navigator.of(context).pop();
|
|
// Navigator.of(context).pop();
|
|
//
|
|
// Navigator.push(
|
|
// context,
|
|
// FadePage(
|
|
// page: ReplySummeryOnReferralPatient(
|
|
// widget.myReferralInPatientModel,
|
|
// replayOnReferralController.text.trim()),
|
|
// ),
|
|
// );
|
|
// }
|
|
// } else {
|
|
// Helpers.showErrorToast("You can't add empty reply");
|
|
// setState(() {
|
|
// isSubmitted = false;
|
|
// });
|
|
// }
|
|
// })),
|
|
],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
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: ListenMode.confirmation,
|
|
localeId: lang == 'en' ? 'en-US' : 'ar-SA',
|
|
);
|
|
} else {
|
|
print("The user has denied the use of speech recognition.");
|
|
}
|
|
}
|
|
|
|
void errorListener(SpeechRecognitionError 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);
|
|
replayOnReferralController.text += reconizedWord + '\n';
|
|
});
|
|
}
|
|
}
|
|
}
|