diff --git a/lib/client/base_app_client.dart b/lib/client/base_app_client.dart new file mode 100644 index 00000000..fa377b90 --- /dev/null +++ b/lib/client/base_app_client.dart @@ -0,0 +1,61 @@ +import 'dart:convert'; + +import 'package:doctor_app_flutter/config/config.dart'; +import 'package:doctor_app_flutter/config/shared_pref_kay.dart'; +import 'package:doctor_app_flutter/interceptor/http_interceptor.dart'; +import 'package:doctor_app_flutter/models/doctor_profile_model.dart'; +import 'package:doctor_app_flutter/util/helpers.dart'; +import 'package:http/http.dart'; + +class BaseAppClient { + static Client client = HttpInterceptor().getClient(); + + static post( + String endPoint, { + Map body, + Function(dynamic response, int statusCode) onSuccess, + Function(String error, int statusCode) onFailure, + }) async { + String url = BASE_URL + endPoint; + try { + Map profile = await sharedPref.getObj(DOCTOR_PROFILE); + String token = await sharedPref.getString(TOKEN); + DoctorProfileModel doctorProfile = DoctorProfileModel.fromJson(profile); + body.containsKey(''); + body['DoctorID'] = doctorProfile.doctorID; + body['EditedBy'] = doctorProfile.doctorID; + body['ProjectID'] = doctorProfile.projectID; + body['ClinicID'] = doctorProfile.clinicID; + body['TokenID'] = token; + body['LanguageID'] = LANGUAGE_ID; + body['stamp'] = STAMP; + body['IPAdress'] = IP_ADDRESS; + body['VersionID'] = VERSION_ID; + body['Channel'] = CHANNEL; + body['SessionID'] = SESSION_ID; + body['IsLoginForDoctorApp'] = IS_LOGIN_FOR_DOCTOR_APP; + body['PatientOutSA'] = PATIENT_OUT_SA; + + if (await Helpers.checkConnection()) { + final response = await client.post(url, body: json.encode(body)); + final int statusCode = response.statusCode; + if (statusCode < 200 || statusCode >= 400 || json == null) { + onFailure('Error While Fetching data', statusCode); + } else { + var parsed = json.decode(response.body.toString()); + if (parsed['MessageStatus'] == 1) { + onSuccess(parsed, statusCode); + } else { + onFailure(parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'], + statusCode); + } + } + } else { + onFailure('Please Check The Internet Connection', -1); + } + } catch (e) { + print(e); + onFailure(e.toString(), -1); + } + } +} diff --git a/lib/config/config.dart b/lib/config/config.dart index 8ebef939..24c2586a 100644 --- a/lib/config/config.dart +++ b/lib/config/config.dart @@ -58,6 +58,6 @@ const STAMP = '2020-04-27T12:17:17.721Z'; const IP_ADDRESS = '11.11.11.11'; const VERSION_ID = 1.2; const CHANNEL = 9; -const SESSION_ID = '2Z7FX4Lokp'; +const SESSION_ID = 'BlUSkYymTt'; const IS_LOGIN_FOR_DOCTOR_APP = true; const PATIENT_OUT_SA = false; diff --git a/lib/main.dart b/lib/main.dart index 869d0b88..98331b4a 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -43,10 +43,12 @@ class MyApp extends StatelessWidget { const Locale('en', ''), // English ], theme: ThemeData( - primarySwatch: Colors.blue, + primarySwatch: Colors.grey, primaryColor: Hexcolor('#B8382C'), buttonColor: Hexcolor('#B8382C'), fontFamily: 'WorkSans', + dividerColor: Colors.grey[200], + backgroundColor: Color.fromRGBO(255,255,255, 1) ), initialRoute: INIT_ROUTE, routes: routes, diff --git a/lib/models/my_referral_patient_model.dart b/lib/models/my_referral_patient_model.dart new file mode 100644 index 00000000..e18dd546 --- /dev/null +++ b/lib/models/my_referral_patient_model.dart @@ -0,0 +1,210 @@ +import 'package:doctor_app_flutter/util/helpers.dart'; + +class MyReferralPatientModel { + int projectID; + int lineItemNo; + int doctorID; + int patientID; + String doctorName; + String doctorNameN; + String firstName; + String middleName; + String lastName; + String firstNameN; + String middleNameN; + String lastNameN; + int gender; + String dateofBirth; + String mobileNumber; + String emailAddress; + String patientIdentificationNo; + int patientType; + String admissionNo; + String admissionDate; + String roomID; + String bedID; + String nursingStationID; + String description; + String nationalityName; + String nationalityNameN; + String clinicDescription; + String clinicDescriptionN; + int referralDoctor; + int referringDoctor; + int referralClinic; + int referringClinic; + int referralStatus; + String referralDate; + String referringDoctorRemarks; + String referredDoctorRemarks; + String referralResponseOn; + int priority; + int frequency; + DateTime mAXResponseTime; + String age; + String frequencyDescription; + String genderDescription; + bool isDoctorLate; + bool isDoctorResponse; + String nursingStationName; + String priorityDescription; + String referringClinicDescription; + String referringDoctorName; + + MyReferralPatientModel( + {this.projectID, + this.lineItemNo, + this.doctorID, + this.patientID, + this.doctorName, + this.doctorNameN, + this.firstName, + this.middleName, + this.lastName, + this.firstNameN, + this.middleNameN, + this.lastNameN, + this.gender, + this.dateofBirth, + this.mobileNumber, + this.emailAddress, + this.patientIdentificationNo, + this.patientType, + this.admissionNo, + this.admissionDate, + this.roomID, + this.bedID, + this.nursingStationID, + this.description, + this.nationalityName, + this.nationalityNameN, + this.clinicDescription, + this.clinicDescriptionN, + this.referralDoctor, + this.referringDoctor, + this.referralClinic, + this.referringClinic, + this.referralStatus, + this.referralDate, + this.referringDoctorRemarks, + this.referredDoctorRemarks, + this.referralResponseOn, + this.priority, + this.frequency, + this.mAXResponseTime, + this.age, + this.frequencyDescription, + this.genderDescription, + this.isDoctorLate, + this.isDoctorResponse, + this.nursingStationName, + this.priorityDescription, + this.referringClinicDescription, + this.referringDoctorName}); + + MyReferralPatientModel.fromJson(Map json) { + projectID = json['ProjectID']; + lineItemNo = json['LineItemNo']; + doctorID = json['DoctorID']; + patientID = json['PatientID']; + doctorName = json['DoctorName']; + doctorNameN = json['DoctorNameN']; + firstName = json['FirstName']; + middleName = json['MiddleName']; + lastName = json['LastName']; + firstNameN = json['FirstNameN']; + middleNameN = json['MiddleNameN']; + lastNameN = json['LastNameN']; + gender = json['Gender']; + dateofBirth = json['DateofBirth']; + mobileNumber = json['MobileNumber']; + emailAddress = json['EmailAddress']; + patientIdentificationNo = json['PatientIdentificationNo']; + patientType = json['PatientType']; + admissionNo = json['AdmissionNo']; + admissionDate = json['AdmissionDate']; + roomID = json['RoomID']; + bedID = json['BedID']; + nursingStationID = json['NursingStationID']; + description = json['Description']; + nationalityName = json['NationalityName']; + nationalityNameN = json['NationalityNameN']; + clinicDescription = json['ClinicDescription']; + clinicDescriptionN = json['ClinicDescriptionN']; + referralDoctor = json['ReferralDoctor']; + referringDoctor = json['ReferringDoctor']; + referralClinic = json['ReferralClinic']; + referringClinic = json['ReferringClinic']; + referralStatus = json['ReferralStatus']; + referralDate = json['ReferralDate']; + referringDoctorRemarks = json['ReferringDoctorRemarks']; + referredDoctorRemarks = json['ReferredDoctorRemarks']; + referralResponseOn = json['ReferralResponseOn']; + priority = json['Priority']; + frequency = json['Frequency']; + mAXResponseTime = Helpers.convertStringToDate(json['MAXResponseTime']); + age = json['Age']; + frequencyDescription = json['FrequencyDescription']; + genderDescription = json['GenderDescription']; + isDoctorLate = json['IsDoctorLate']; + isDoctorResponse = json['IsDoctorResponse']; + nursingStationName = json['NursingStationName']; + priorityDescription = json['PriorityDescription']; + referringClinicDescription = json['ReferringClinicDescription']; + referringDoctorName = json['ReferringDoctorName']; + } + + Map toJson() { + final Map data = new Map(); + data['ProjectID'] = this.projectID; + data['LineItemNo'] = this.lineItemNo; + data['DoctorID'] = this.doctorID; + data['PatientID'] = this.patientID; + data['DoctorName'] = this.doctorName; + data['DoctorNameN'] = this.doctorNameN; + data['FirstName'] = this.firstName; + data['MiddleName'] = this.middleName; + data['LastName'] = this.lastName; + data['FirstNameN'] = this.firstNameN; + data['MiddleNameN'] = this.middleNameN; + data['LastNameN'] = this.lastNameN; + data['Gender'] = this.gender; + data['DateofBirth'] = this.dateofBirth; + data['MobileNumber'] = this.mobileNumber; + data['EmailAddress'] = this.emailAddress; + data['PatientIdentificationNo'] = this.patientIdentificationNo; + data['PatientType'] = this.patientType; + data['AdmissionNo'] = this.admissionNo; + data['AdmissionDate'] = this.admissionDate; + data['RoomID'] = this.roomID; + data['BedID'] = this.bedID; + data['NursingStationID'] = this.nursingStationID; + data['Description'] = this.description; + data['NationalityName'] = this.nationalityName; + data['NationalityNameN'] = this.nationalityNameN; + data['ClinicDescription'] = this.clinicDescription; + data['ClinicDescriptionN'] = this.clinicDescriptionN; + data['ReferralDoctor'] = this.referralDoctor; + data['ReferringDoctor'] = this.referringDoctor; + data['ReferralClinic'] = this.referralClinic; + data['ReferringClinic'] = this.referringClinic; + data['ReferralStatus'] = this.referralStatus; + data['ReferralDate'] = this.referralDate; + data['ReferringDoctorRemarks'] = this.referringDoctorRemarks; + data['ReferredDoctorRemarks'] = this.referredDoctorRemarks; + data['ReferralResponseOn'] = this.referralResponseOn; + data['Priority'] = this.priority; + data['Frequency'] = this.frequency; + data['MAXResponseTime'] = this.mAXResponseTime; + data['Age'] = this.age; + data['FrequencyDescription'] = this.frequencyDescription; + data['GenderDescription'] = this.genderDescription; + data['IsDoctorLate'] = this.isDoctorLate; + data['IsDoctorResponse'] = this.isDoctorResponse; + data['NursingStationName'] = this.nursingStationName; + data['PriorityDescription'] = this.priorityDescription; + data['ReferringClinicDescription'] = this.referringClinicDescription; + data['ReferringDoctorName'] = this.referringDoctorName; + return data; + } +} diff --git a/lib/models/request_add_referred_doctor_remarks.dart b/lib/models/request_add_referred_doctor_remarks.dart new file mode 100644 index 00000000..0799c7ba --- /dev/null +++ b/lib/models/request_add_referred_doctor_remarks.dart @@ -0,0 +1,78 @@ +import 'package:doctor_app_flutter/config/config.dart'; + +class RequestAddReferredDoctorRemarks { + int projectID; + String admissionNo; + int lineItemNo; + String referredDoctorRemarks; + int editedBy; + int patientID; + int referringDoctor; + int languageID; + String stamp; + String iPAdress; + double versionID; + int channel; + String tokenID; + String sessionID; + bool isLoginForDoctorApp; + bool patientOutSA; + + RequestAddReferredDoctorRemarks( + {this.projectID, + this.admissionNo, + this.lineItemNo, + this.referredDoctorRemarks, + this.editedBy, + this.patientID, + this.referringDoctor, + this.languageID = LANGUAGE_ID, + this.stamp = STAMP, + this.iPAdress = IP_ADDRESS, + this.versionID = VERSION_ID, + this.channel= CHANNEL, + this.tokenID, + this.sessionID = SESSION_ID, + this.isLoginForDoctorApp = IS_LOGIN_FOR_DOCTOR_APP, + this.patientOutSA = PATIENT_OUT_SA}); + + RequestAddReferredDoctorRemarks.fromJson(Map json) { + projectID = json['ProjectID']; + admissionNo = json['AdmissionNo']; + lineItemNo = json['LineItemNo']; + referredDoctorRemarks = json['ReferredDoctorRemarks']; + editedBy = json['EditedBy']; + patientID = json['PatientID']; + referringDoctor = json['ReferringDoctor']; + languageID = json['LanguageID']; + stamp = json['stamp']; + iPAdress = json['IPAdress']; + versionID = json['VersionID']; + channel = json['Channel']; + tokenID = json['TokenID']; + sessionID = json['SessionID']; + isLoginForDoctorApp = json['IsLoginForDoctorApp']; + patientOutSA = json['PatientOutSA']; + } + + Map toJson() { + final Map data = new Map(); + data['ProjectID'] = this.projectID; + data['AdmissionNo'] = this.admissionNo; + data['LineItemNo'] = this.lineItemNo; + data['ReferredDoctorRemarks'] = this.referredDoctorRemarks; + data['EditedBy'] = this.editedBy; + data['PatientID'] = this.patientID; + data['ReferringDoctor'] = this.referringDoctor; + data['LanguageID'] = this.languageID; + data['stamp'] = this.stamp; + data['IPAdress'] = this.iPAdress; + data['VersionID'] = this.versionID; + data['Channel'] = this.channel; + data['TokenID'] = this.tokenID; + data['SessionID'] = this.sessionID; + data['IsLoginForDoctorApp'] = this.isLoginForDoctorApp; + data['PatientOutSA'] = this.patientOutSA; + return data; + } +} diff --git a/lib/models/request_doctor_reply.dart b/lib/models/request_doctor_reply.dart index fbbe4697..707336d6 100644 --- a/lib/models/request_doctor_reply.dart +++ b/lib/models/request_doctor_reply.dart @@ -15,18 +15,18 @@ class RequestDoctorReply { bool patientOutSA; RequestDoctorReply( - {this.projectID =15 , - this.doctorID =70907 , - this.transactionNo = TRANSACTION_NO, - this.languageID = LANGUAGE_ID, - this.stamp = STAMP, - this.iPAdress = IP_ADDRESS, - this.versionID = VERSION_ID, - this.channel = CHANNEL, - this.tokenID ='@dm!n' , - this.sessionID = SESSION_ID, - this.isLoginForDoctorApp = IS_LOGIN_FOR_DOCTOR_APP, - this.patientOutSA = PATIENT_OUT_SA}); + {this.projectID , + this.doctorID , + this.transactionNo = TRANSACTION_NO , + this.languageID , + this.stamp , + this.iPAdress, + this.versionID , + this.channel, + this.tokenID , + this.sessionID, + this.isLoginForDoctorApp , + this.patientOutSA }); RequestDoctorReply.fromJson(Map json) { projectID = json['ProjectID']; diff --git a/lib/models/request_my_referral_patient_model.dart b/lib/models/request_my_referral_patient_model.dart new file mode 100644 index 00000000..adaf9e5c --- /dev/null +++ b/lib/models/request_my_referral_patient_model.dart @@ -0,0 +1,94 @@ +import 'package:doctor_app_flutter/config/config.dart'; + +class RequestMyReferralPatientModel { + int projectID; + int clinicID; + int doctorID; + String firstName; + String middleName; + String lastName; + String patientMobileNumber; + String patientIdentificationID; + int patientID; + String from; + String to; + int languageID; + String stamp; + String iPAdress; + double versionID; + int channel; + String tokenID; + String sessionID; + bool isLoginForDoctorApp; + bool patientOutSA; + + RequestMyReferralPatientModel( + {this.projectID, + this.clinicID, + this.doctorID, + this.firstName = "0", + this.middleName = "0", + this.lastName = "0", + this.patientMobileNumber = "0", + this.patientIdentificationID = "0", + this.patientID = 0, + this.from = "0", + this.to = "0", + this.languageID , + this.stamp , + this.iPAdress , + this.versionID , + this.channel , + this.tokenID, + this.sessionID , + this.isLoginForDoctorApp , + this.patientOutSA }); + + RequestMyReferralPatientModel.fromJson(Map json) { + projectID = json['ProjectID']; + clinicID = json['ClinicID']; + doctorID = json['DoctorID']; + firstName = json['FirstName']; + middleName = json['MiddleName']; + lastName = json['LastName']; + patientMobileNumber = json['PatientMobileNumber']; + patientIdentificationID = json['PatientIdentificationID']; + patientID = json['PatientID']; + from = json['From']; + to = json['To']; + languageID = json['LanguageID']; + stamp = json['stamp']; + iPAdress = json['IPAdress']; + versionID = json['VersionID']; + channel = json['Channel']; + tokenID = json['TokenID']; + sessionID = json['SessionID']; + isLoginForDoctorApp = json['IsLoginForDoctorApp']; + patientOutSA = json['PatientOutSA']; + } + + Map toJson() { + final Map data = new Map(); + data['ProjectID'] = this.projectID; + data['ClinicID'] = this.clinicID; + data['DoctorID'] = this.doctorID; + data['FirstName'] = this.firstName; + data['MiddleName'] = this.middleName; + data['LastName'] = this.lastName; + data['PatientMobileNumber'] = this.patientMobileNumber; + data['PatientIdentificationID'] = this.patientIdentificationID; + data['PatientID'] = this.patientID; + data['From'] = this.from; + data['To'] = this.to; + data['LanguageID'] = this.languageID; + data['stamp'] = this.stamp; + data['IPAdress'] = this.iPAdress; + data['VersionID'] = this.versionID; + data['Channel'] = this.channel; + data['TokenID'] = this.tokenID; + data['SessionID'] = this.sessionID; + data['IsLoginForDoctorApp'] = this.isLoginForDoctorApp; + data['PatientOutSA'] = this.patientOutSA; + return data; + } +} diff --git a/lib/models/request_schedule.dart b/lib/models/request_schedule.dart index d704e9bb..949f07eb 100644 --- a/lib/models/request_schedule.dart +++ b/lib/models/request_schedule.dart @@ -16,21 +16,21 @@ class RequestSchedule { bool patientOutSA; int patientTypeID; - RequestSchedule({ - this.projectID, - this.clinicID, - this.doctorID, - this.doctorWorkingHoursDays = 7, - this.languageID = LANGUAGE_ID, - this.stamp = STAMP, - this.iPAdress = IP_ADDRESS, - this.versionID = VERSION_ID, - this.channel = CHANNEL, - this.tokenID, - this.sessionID = SESSION_ID, - this.isLoginForDoctorApp = IS_LOGIN_FOR_DOCTOR_APP, - this.patientOutSA = PATIENT_OUT_SA, - this.patientTypeID = 1}); + RequestSchedule( + {this.projectID, + this.clinicID, + this.doctorID, + this.doctorWorkingHoursDays = 7, + this.languageID, + this.stamp, + this.iPAdress, + this.versionID, + this.channel, + this.tokenID, + this.sessionID, + this.isLoginForDoctorApp, + this.patientOutSA, + this.patientTypeID = 1}); RequestSchedule.fromJson(Map json) { projectID = json['ProjectID']; diff --git a/lib/providers/doctor_reply_provider.dart b/lib/providers/doctor_reply_provider.dart index 1d2add69..c7e48afa 100644 --- a/lib/providers/doctor_reply_provider.dart +++ b/lib/providers/doctor_reply_provider.dart @@ -1,22 +1,12 @@ -import 'dart:convert'; - -import 'package:doctor_app_flutter/config/config.dart'; -import 'package:doctor_app_flutter/config/shared_pref_kay.dart'; -import 'package:doctor_app_flutter/models/doctor_profile_model.dart'; +import 'package:doctor_app_flutter/client/base_app_client.dart'; import 'package:doctor_app_flutter/models/request_doctor_reply.dart'; import 'package:doctor_app_flutter/models/list_gt_my_pationents_question_model.dart'; -import 'package:doctor_app_flutter/util/helpers.dart'; import 'package:flutter/cupertino.dart'; -import 'package:http/http.dart'; -import 'package:http_interceptor/http_client_with_interceptor.dart'; -import '../interceptor/http_interceptor.dart'; class DoctorReplyProvider with ChangeNotifier { - Client client = - HttpClientWithInterceptor.build(interceptors: [HttpInterceptor()]); - List listDoctorWorkingHoursTable = []; + bool isLoading = true; bool isError = false; String error = ''; @@ -27,41 +17,22 @@ class DoctorReplyProvider with ChangeNotifier { } getDoctorReply() async { - const url = 'https://hmgwebservices.com/Services/DoctorApplication.svc/REST/GtMyPatientsQuestions'; - Map profile = await sharedPref.getObj(DOCTOR_PROFILE); - String token = await sharedPref.getString(TOKEN); - DoctorProfileModel doctorProfile = DoctorProfileModel.fromJson(profile); -// _requestDoctorReply.doctorID = doctorProfile.doctorID; -// _requestDoctorReply.projectID = doctorProfile.projectID; -// _requestDoctorReply.tokenID = token; try { - if (await Helpers.checkConnection()) { - final response = await client.post(url, - body: json.encode(_requestDoctorReply.toJson())); - final int statusCode = response.statusCode; - if (statusCode < 200 || statusCode >= 400 || json == null) { - isLoading = false; - isError = true; - error = 'Error While Fetching data'; - } else { - var parsed = json.decode(response.body.toString()); - if (parsed['MessageStatus'] == 1) { - parsed['List_GtMyPatientsQuestions'].forEach((v) { - listDoctorWorkingHoursTable.add( ListGtMyPatientsQuestions.fromJson(v)); - }); + await BaseAppClient.post('DoctorApplication.svc/REST/GtMyPatientsQuestions', + body: _requestDoctorReply.toJson(), + onSuccess: (dynamic response, int statusCode) { + response['List_GtMyPatientsQuestions'].forEach((v) { + listDoctorWorkingHoursTable.add(ListGtMyPatientsQuestions.fromJson(v)); isError = false; isLoading = false; - } else { - isError = true; - isLoading = false; - error = parsed['ErrorEndUserMessage'] ?? parsed['ErrorMessage'] ; - } - } - } else { - isLoading = false; - isError = true; - error = 'Please Check The Internet Connection'; - } + }); + }, + onFailure: (String error, int statusCode) { + isError = true; + isLoading = false; + this.error= error; + }); + notifyListeners(); } catch (error) { throw error; diff --git a/lib/providers/referral_patient_provider.dart b/lib/providers/referral_patient_provider.dart new file mode 100644 index 00000000..782bced7 --- /dev/null +++ b/lib/providers/referral_patient_provider.dart @@ -0,0 +1,74 @@ +import 'package:doctor_app_flutter/client/base_app_client.dart'; +import 'package:doctor_app_flutter/models/my_referral_patient_model.dart'; +import 'package:doctor_app_flutter/models/request_add_referred_doctor_remarks.dart'; +import 'package:doctor_app_flutter/models/request_my_referral_patient_model.dart'; +import 'package:flutter/cupertino.dart'; + + +class MyReferralPatientProvider with ChangeNotifier { + List listMyReferralPatientModel = []; + + bool isLoading = true; + bool isError = false; + String error = ''; + + RequestMyReferralPatientModel _requestMyReferralPatient = RequestMyReferralPatientModel(); + RequestAddReferredDoctorRemarks _requestAddReferredDoctorRemarks = RequestAddReferredDoctorRemarks(); + + MyReferralPatientProvider() { + getMyReferralPatient(); + } + + getMyReferralPatient() async { + try { + await BaseAppClient.post( + 'DoctorApplication.svc/REST/GtMyReferralPatient', + body: _requestMyReferralPatient.toJson(), + onSuccess: (dynamic response, int statusCode) { + response['List_MyReferralPatient'].forEach((v) { + listMyReferralPatientModel.add(MyReferralPatientModel.fromJson(v)); + }); + isError = false; + isLoading = false; + }, + onFailure: (String error, int statusCode) { + isError = true; + isLoading = false; + this.error = error; + }, + ); + notifyListeners(); + } catch (error) { + isLoading = false; + isError = true; + this.error = 'Something wrong happened, please contact the admin'; + notifyListeners(); + } + } + + Future replay( + String referredDoctorRemarks, MyReferralPatientModel model) async { + try { + _requestAddReferredDoctorRemarks.admissionNo = model.admissionNo; + _requestAddReferredDoctorRemarks.patientID = model.patientID; + _requestAddReferredDoctorRemarks.referredDoctorRemarks = referredDoctorRemarks; + _requestAddReferredDoctorRemarks.lineItemNo = model.lineItemNo; + _requestAddReferredDoctorRemarks.referringDoctor = model.referringDoctor; + await BaseAppClient.post( + 'DoctorApplication.svc/REST/AddReferredDoctorRemarks', + body: _requestAddReferredDoctorRemarks.toJson(), + onSuccess: (dynamic body, int statusCode) { + model.referredDoctorRemarks = referredDoctorRemarks; + listMyReferralPatientModel[ + listMyReferralPatientModel.indexOf(model)] = model; + notifyListeners(); + }, + onFailure: (String error, int statusCode) { + throw (error); + }, + ); + } catch (error) { + throw error; + } + } +} diff --git a/lib/providers/schedule_provider.dart b/lib/providers/schedule_provider.dart index 65945f52..057219a1 100644 --- a/lib/providers/schedule_provider.dart +++ b/lib/providers/schedule_provider.dart @@ -1,21 +1,9 @@ -import 'dart:convert'; - -import 'package:doctor_app_flutter/config/config.dart'; -import 'package:doctor_app_flutter/config/shared_pref_kay.dart'; -import 'package:doctor_app_flutter/models/doctor_profile_model.dart'; -import 'package:doctor_app_flutter/util/helpers.dart'; +import 'package:doctor_app_flutter/client/base_app_client.dart'; import 'package:flutter/cupertino.dart'; -import 'package:http/http.dart'; -import 'package:http_interceptor/http_client_with_interceptor.dart'; - -import '../interceptor/http_interceptor.dart'; import '../models/list_doctor_working_hours_table_model.dart'; import '../models/request_schedule.dart'; class ScheduleProvider with ChangeNotifier { - - Client client = HttpClientWithInterceptor.build(interceptors: [HttpInterceptor()]); - List listDoctorWorkingHoursTable = []; bool isLoading = true; bool isError = false; @@ -27,41 +15,26 @@ class ScheduleProvider with ChangeNotifier { } getDoctorSchedule() async { - const url = BASE_URL + 'Doctors.svc/REST/GetDoctorWorkingHoursTable'; - Map profile = await sharedPref.getObj(DOCTOR_PROFILE); - String token = await sharedPref.getString(TOKEN); - DoctorProfileModel doctorProfile = DoctorProfileModel.fromJson(profile); - requestSchedule.doctorID = doctorProfile.doctorID; - requestSchedule.projectID = doctorProfile.projectID; - requestSchedule.clinicID = doctorProfile.clinicID; - requestSchedule.tokenID = token; try { - - if (await Helpers.checkConnection()) { - final response = await client.post(url, body: json.encode(requestSchedule.toJson())); - final int statusCode = response.statusCode; - if (statusCode < 200 || statusCode >= 400 || json == null) { - isLoading = false; - isError = true; - error = 'Error While Fetching data'; - } else { - var parsed = json.decode(response.body.toString()); - parsed['List_DoctorWorkingHoursTable'].forEach((v) { - listDoctorWorkingHoursTable - .add(new ListDoctorWorkingHoursTable.fromJson(v)); - }); - isError = false; - isLoading = false; - } - } else { + await BaseAppClient.post('Doctors.svc/REST/GetDoctorWorkingHoursTable', + body: requestSchedule.toJson(), + onSuccess: (dynamic response, int statusCode) { + response['List_DoctorWorkingHoursTable'].forEach((v) { + listDoctorWorkingHoursTable.add(new ListDoctorWorkingHoursTable.fromJson(v)); + }); + isError = false; + isLoading = false; + }, onFailure: (String error, int statusCode) { isLoading = false; isError = true; - error = 'Please Check The Internet Connection'; - } - + this.error = error; + }); + notifyListeners(); + } catch (e) { + isLoading = false; + isError = true; + error = 'Something wrong happened, please contact the admin'; notifyListeners(); - } catch (error) { - throw error; } } } diff --git a/lib/screens/dashboard_screen.dart b/lib/screens/dashboard_screen.dart index 2146e547..d2a777f1 100644 --- a/lib/screens/dashboard_screen.dart +++ b/lib/screens/dashboard_screen.dart @@ -2,6 +2,7 @@ import 'package:doctor_app_flutter/config/size_config.dart'; import 'package:doctor_app_flutter/providers/doctor_reply_provider.dart'; import 'package:doctor_app_flutter/providers/medicine_provider.dart'; import 'package:doctor_app_flutter/providers/hospital_provider.dart'; +import 'package:doctor_app_flutter/providers/referral_patient_provider.dart'; import 'package:doctor_app_flutter/screens/medicine/medicine_search_screen.dart'; import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart'; @@ -16,6 +17,7 @@ import '../widgets/dashboard/dashboard_item_icons_texts.dart'; import '../widgets/dashboard/dashboard_item_texts_widget.dart'; import '../widgets/shared/rounded_container_widget.dart'; import 'doctor/doctor_reply_screen.dart'; +import 'doctor/my_referral_patient_screen.dart'; class DashboardScreen extends StatefulWidget { DashboardScreen({Key key, this.title}) : super(key: key); @@ -271,12 +273,25 @@ class _DashboardScreenState extends State { ), Expanded( flex: 2, - child: new DashboardItemIconText( - DoctorApp.home_icon, - "", - "Discharge Patient", - showBorder: false, - backgroundColor: Colors.brown[400], + child: InkWell( + onTap: (){ + Navigator.push( + context, + MaterialPageRoute( + builder: (context) => ChangeNotifierProvider( + create: (_) => MyReferralPatientProvider(), + child: MyReferralPatient(), + ), + ), + ); + }, + child: DashboardItemIconText( + DoctorApp.home_icon, + "", + "My Referral Patient", + showBorder: false, + backgroundColor: Colors.brown[400], + ), ), ), ], diff --git a/lib/screens/doctor/my_referral_patient_screen.dart b/lib/screens/doctor/my_referral_patient_screen.dart new file mode 100644 index 00000000..e2e10e82 --- /dev/null +++ b/lib/screens/doctor/my_referral_patient_screen.dart @@ -0,0 +1,65 @@ +import 'package:doctor_app_flutter/providers/referral_patient_provider.dart'; +import 'package:doctor_app_flutter/providers/schedule_provider.dart'; +import 'package:doctor_app_flutter/util/translations_delegate_base.dart'; +import 'package:doctor_app_flutter/widgets/doctor/my_referral_patient_widget.dart'; +import 'package:doctor_app_flutter/widgets/doctor/my_schedule_widget.dart'; +import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart'; +import 'package:doctor_app_flutter/widgets/shared/dr_app_circular_progress_Indeicator.dart'; +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; + +import '../../widgets/shared/app_scaffold_widget.dart'; + +class MyReferralPatient extends StatelessWidget { + MyReferralPatientProvider referralPatientProvider; + + @override + Widget build(BuildContext context) { + referralPatientProvider = Provider.of(context); + return AppScaffold( + showBottomBar: false, + showAppDrawer: false, + appBarTitle: TranslationBase.of(context).mySchedule, + body: referralPatientProvider.isLoading + ? DrAppCircularProgressIndeicator() + : referralPatientProvider.isError + ? Center( + child: AppText( + referralPatientProvider.error, + color: Theme.of(context).errorColor, + ), + ) + : referralPatientProvider.listMyReferralPatientModel.length == 0 + ? Center( + child: AppText( + TranslationBase.of(context).errorNoSchedule, + color: Theme.of(context).errorColor, + ), + ) + : Container( + padding: EdgeInsetsDirectional.fromSTEB(20, 0, 20, 0), + child: ListView( + children: [ + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + SizedBox( + height: 10, + ), + Container( + child: Column( + children: referralPatientProvider.listMyReferralPatientModel.map((item) { + return MyReferralPatientWidget( + myReferralPatientModel: item, + ); + }).toList(), + ), + ), + ], + ), + ], + ), + ), + ); + } +} diff --git a/lib/screens/doctor/my_schedule_screen.dart b/lib/screens/doctor/my_schedule_screen.dart index 711e2642..dd40dada 100644 --- a/lib/screens/doctor/my_schedule_screen.dart +++ b/lib/screens/doctor/my_schedule_screen.dart @@ -1,16 +1,13 @@ import 'package:doctor_app_flutter/providers/schedule_provider.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/doctor/my_schedule_widget.dart'; import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart'; -import 'package:doctor_app_flutter/widgets/shared/card_with_bgNew_widget.dart'; import 'package:doctor_app_flutter/widgets/shared/dr_app_circular_progress_Indeicator.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import '../../config/size_config.dart'; import '../../widgets/shared/app_scaffold_widget.dart'; -import '../../widgets/shared/card_with_bg_widget.dart'; class MyScheduleScreen extends StatelessWidget { ScheduleProvider scheduleProvider; @@ -83,8 +80,4 @@ class MyScheduleScreen extends StatelessWidget { ); } - TextStyle textStyle(size, [FontWeight weight]) { - return TextStyle( - fontSize: size * SizeConfig.textMultiplier, fontWeight: weight); - } } diff --git a/lib/util/helpers.dart b/lib/util/helpers.dart index 45ad043d..2ca362b5 100644 --- a/lib/util/helpers.dart +++ b/lib/util/helpers.dart @@ -245,6 +245,24 @@ class Helpers { else return ""; } + /* + *@author: Mohammad Aljammal + *@Date:26/5/2020 + *@param: DateTime + *@return: data formatted like 26/4/2020 + *@desc: convert DateTime to data formatted + */ + static String getDateFormatted(DateTime dateTime) { + print(dateTime); + if (dateTime != null) + return dateTime.day.toString() + + "/" + + dateTime.month.toString() + + "/" + + dateTime.year.toString(); + else + return ""; + } /* *@author: Mohammad Aljammal diff --git a/lib/widgets/doctor/my_referral_patient_widget.dart b/lib/widgets/doctor/my_referral_patient_widget.dart new file mode 100644 index 00000000..27517758 --- /dev/null +++ b/lib/widgets/doctor/my_referral_patient_widget.dart @@ -0,0 +1,342 @@ +import 'package:doctor_app_flutter/config/size_config.dart'; +import 'package:doctor_app_flutter/models/my_referral_patient_model.dart'; +import 'package:doctor_app_flutter/providers/referral_patient_provider.dart'; +import 'package:doctor_app_flutter/util/helpers.dart'; +import 'package:doctor_app_flutter/widgets/shared/Text.dart'; +import 'package:doctor_app_flutter/widgets/shared/TextFields.dart'; +import 'package:doctor_app_flutter/widgets/shared/app_button.dart'; +import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart'; +import 'package:doctor_app_flutter/widgets/shared/card_with_bgNew_widget.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; + +class MyReferralPatientWidget extends StatefulWidget { + final MyReferralPatientModel myReferralPatientModel; + + MyReferralPatientWidget({Key key, this.myReferralPatientModel}); + + @override + _MyReferralPatientWidgetState createState() => + _MyReferralPatientWidgetState(); +} + +class _MyReferralPatientWidgetState extends State { + bool _showDetails = false; + bool _isLoading = false; + final _formKey = GlobalKey(); + String _referredDoctorRemarks; + String error; + TextEditingController answerController; + + @override + void initState() { + answerController = new TextEditingController(text: widget.myReferralPatientModel.referredDoctorRemarks ?? ''); + super.initState(); + } + + @override + Widget build(BuildContext context) { + return CardWithBgWidgetNew( + widget: Container( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceAround, + children: [ + AppText( + '${widget.myReferralPatientModel.firstName} ${widget.myReferralPatientModel.lastName}', + fontSize: 2.5 * SizeConfig.textMultiplier, + fontWeight: FontWeight.bold, + ), + InkWell( + onTap: () { + setState(() { + _showDetails = !_showDetails; + }); + }, + child: Icon(_showDetails + ? Icons.keyboard_arrow_up + : Icons.keyboard_arrow_down)), + ], + ), + !_showDetails + ? Container() + : AnimatedContainer( + duration: Duration(milliseconds: 200), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Divider(color: Colors.grey), + Row( + children: [ + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + AppText( + 'File No', + fontSize: + 1.7 * SizeConfig.textMultiplier, + fontWeight: FontWeight.bold, + ), + AppText( + '${widget.myReferralPatientModel.referringDoctor}', + fontSize: + 1.7 * SizeConfig.textMultiplier, + fontWeight: FontWeight.w300, + ) + ], + ), + + ), + Container( + height: SizeConfig.realScreenWidth * 0.1, + width: 0.8, + color: Colors.grey, + margin: EdgeInsets.only(left: 15, right: 15), + ), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + AppText( + 'Referring Doctor', + fontSize: + 1.7 * SizeConfig.textMultiplier, + fontWeight: FontWeight.bold, + ), + AppText( + widget.myReferralPatientModel + .referringClinicDescription, + fontSize: + 1.7 * SizeConfig.textMultiplier, + fontWeight: FontWeight.w300, + ) + ], + ), + ), + ], + ), + + Divider(color: Colors.grey), + Row( + children: [ + Expanded( + child: Column( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + AppText( + 'Referring Clinic', + fontSize: + 1.7 * SizeConfig.textMultiplier, + fontWeight: FontWeight.bold, + ), + AppText( + '${widget.myReferralPatientModel.referringClinicDescription}', + fontSize: + 1.7 * SizeConfig.textMultiplier, + fontWeight: FontWeight.w300, + ) + ], + ), + ), + Container( + height: SizeConfig.realScreenWidth * 0.1, + width: 0.8, + color: Colors.grey, + margin: EdgeInsets.only(left: 15, right: 15), + ), + Expanded( + child: Column( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + AppText( + 'Frequency', + fontSize: + 1.7 * SizeConfig.textMultiplier, + fontWeight: FontWeight.bold, + ), + AppText( + widget.myReferralPatientModel + .frequencyDescription, + fontSize: + 1.7 * SizeConfig.textMultiplier, + fontWeight: FontWeight.w300, + ) + ], + ), + ), + ], + ), + Divider(color: Colors.grey), + Row( + children: [ + Expanded( + child: Column( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + AppText( + 'Priority', + fontSize: + 1.7 * SizeConfig.textMultiplier, + fontWeight: FontWeight.bold, + ), + AppText( + '${widget.myReferralPatientModel.priorityDescription}', + fontSize: + 1.7 * SizeConfig.textMultiplier, + fontWeight: FontWeight.w300, + ) + ], + ), + ), + Container( + height: SizeConfig.realScreenWidth * 0.1, + width: 0.8, + color: Colors.grey, + margin: EdgeInsets.only(left: 15, right: 15), + ), + Expanded( + child: Column( + crossAxisAlignment: + CrossAxisAlignment.start, + children: [ + AppText( + 'Max Response Time', + fontSize: + 1.7 * SizeConfig.textMultiplier, + fontWeight: FontWeight.bold, + ), + AppText( + Helpers.getDateFormatted(widget + .myReferralPatientModel + .mAXResponseTime), + fontSize: + 1.7 * SizeConfig.textMultiplier, + fontWeight: FontWeight.w300, + ) + ], + ), + ), + ], + ), + Divider(color: Colors.grey), + AppText( + 'Clinic Details and Remarks', + fontSize: 1.7 * SizeConfig.textMultiplier, + fontWeight: FontWeight.bold, + textAlign: TextAlign.start, + ), + SizedBox( + height: 5, + ), + Texts( + '73 years old female known case of HTN and dm on regular medication one day prior the patient had rt sided weakness suddenly and reduced level of conscoiusness no vomting no headache no bluriing of vision no other relevant symptoms.\r\nPMH:No history of similar condition no history of surgey or blood transfusions\r\nCT brain was done apparently effaced left insular cortex', + style: "bodyText1", + readMore: true, + textAlign: TextAlign.start, + maxLength: 100), + SizedBox( + height: 5, + ), + AppText( + 'Answer/Suggestions', + fontSize: 1.7 * SizeConfig.textMultiplier, + fontWeight: FontWeight.bold, + textAlign: TextAlign.start, + ), + SizedBox( + height: 5, + ), + Form( + key: _formKey, + child: TextFields( + maxLines: 2, + minLines: 2, + hintText: 'Answer the patient', + initialValue: widget.myReferralPatientModel.referredDoctorRemarks ?? '', + readOnly: _isLoading, + validator: (value) { + if (value.isEmpty) + return "please enter answer"; + else + return null; + }, + onSubmit: (value) { + _referredDoctorRemarks = value; + }, + ), + ), + SizedBox(height: 10.0), + if (error != null && error.isNotEmpty) + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(6.0), + color: Theme.of(context) + .errorColor + .withOpacity(0.06), + ), + padding: EdgeInsets.symmetric( + vertical: 8.0, horizontal: 12.0), + child: Row( + children: [ + Expanded( + child: Texts(error ?? "", + style: "bodyText1", + color: Theme.of(context) + .errorColor)), + ], + ), + ), + SizedBox(height: 10.0), + ], + ), + SizedBox(height: 10.0), + Container( + width: double.infinity, + child: Button( + onTap: () async { + final form = _formKey.currentState; + if (form.validate()) { + setState(() { + _isLoading = true; + }); + try { + await Provider.of(context, listen: false).replay(answerController.text.toString(), widget.myReferralPatientModel); + setState(() { + _isLoading = false; + }); + } catch (e) { + setState(() { + error = e.toString(); + _isLoading = false; + }); + } + } + }, + title: 'Reply', + loading: _isLoading, + ), + ) + ], + ) + ], + ), + ) + ], + ), + ), + ); + } +} diff --git a/lib/widgets/shared/Text.dart b/lib/widgets/shared/Text.dart new file mode 100644 index 00000000..76402617 --- /dev/null +++ b/lib/widgets/shared/Text.dart @@ -0,0 +1,239 @@ +import 'package:flutter/material.dart'; +import 'package:hexcolor/hexcolor.dart'; + +class Texts extends StatefulWidget { + + final String text; + final String variant; + final Color color; + final bool bold; + final bool regular; + final bool medium; + final int maxLength; + final bool italic; + final TextAlign textAlign; + final int maxLines; + final bool readMore; + final String style; + final bool allowExpand; + + Texts(this.text, {Key key, this.variant, this.color, + this.bold, this.regular, this.medium, this.allowExpand = true, + this.italic:false, this.textAlign, this.maxLength=60, + this.maxLines, this.readMore=false, this.style + }) : super(key: key); + + @override + _TextsState createState() => _TextsState(); +} + +class _TextsState extends State { + bool hidden = false; + String text = ""; + + @override + void didUpdateWidget(Texts oldWidget) { + setState(() { + if (widget.style=="overline") + text = widget.text.toUpperCase(); + else { + text = widget.text; + } + }); + super.didUpdateWidget(oldWidget); + } + + @override + void initState() { + hidden = widget.readMore; + if (widget.style=="overline") + text = widget.text.toUpperCase(); + else { + text = widget.text; + } + super.initState(); + } + + double _getFontSize () { + switch (widget.variant) { + case "heading0": + return 40.0; + case "heading": + return 32.0; + case "heading2": + return 28.0; + case "heading3": + return 18.0; + case "body1": + return 18.0; + case "body2": + return 20.0; + case "body2Link": + return 16.0; + case "caption": + return 16.0; + case "caption2": + return 14.0; + case "bodyText": + return 15.0; + case "bodyText2": + return 17.0; + case "caption3": + return 12.0; + case "caption4": + return 9.0; + case "overline": + return 11.0; + case "date": + return 24.0; + default: + return 16.0; + } + } + + FontWeight _getFontWeight () { + if (widget.bold ?? false) { + return FontWeight.w900; + } else if (widget.regular ?? false) { + return FontWeight.w500; + } else if (widget.medium ?? false) { + return FontWeight.w800; + } + else { + if (widget.style==null) { + switch (widget.variant) { + case "heading": + return FontWeight.w900; + case "heading2": + return FontWeight.w900; + case "heading3": + return FontWeight.w900; + case "body1": + return FontWeight.w800; + case "body2": + return FontWeight.w900; + case "body2Link": + return FontWeight.w800; + case "caption": + return FontWeight.w700; + case "caption2": + return FontWeight.w700; + case "bodyText": + return FontWeight.w500; + case "bodyText2": + return FontWeight.w500; + case "caption3": + return FontWeight.w600; + case "caption4": + return FontWeight.w600; + case "overline": + return FontWeight.w800; + case "date": + return FontWeight.w900; + default: + return FontWeight.w500; + } + } else { + return null; + } + + } + } + + @override + Widget build(BuildContext context) { + + TextStyle _getFontStyle () { + switch (widget.style) { + case "headline2": + return Theme.of(context).textTheme.headline2; + case "headline3": + return Theme.of(context).textTheme.headline3; + case "headline4": + return Theme.of(context).textTheme.headline4; + case "headline5": + return Theme.of(context).textTheme.headline5; + case "headline6": + return Theme.of(context).textTheme.headline6; + case "bodyText2": + return Theme.of(context).textTheme.bodyText2; + case "bodyText_15": + return Theme.of(context).textTheme.bodyText2.copyWith(fontSize: 15.0); + case "bodyText1": + return Theme.of(context).textTheme.bodyText1; + case "caption": + return Theme.of(context).textTheme.caption; + case "overline": + return Theme.of(context).textTheme.overline; + case "button": + return Theme.of(context).textTheme.button; + default : + return TextStyle(); + } + } + + return Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Stack( + children: [ + Text(!hidden ? text : (text.substring(0, text.length > widget.maxLength ? widget.maxLength : text.length)), + textAlign: widget.textAlign, + overflow: widget.maxLines!=null ? ((widget.maxLines > 1) ? TextOverflow.fade : TextOverflow.ellipsis) : null, + maxLines: widget.maxLines ?? null, + style: widget.style != null ? _getFontStyle().copyWith( + fontStyle: widget.italic ? FontStyle.italic : null, + color: widget.color!=null ? widget.color : null, + fontWeight: _getFontWeight(), + ) : TextStyle( + fontStyle: widget.italic ? FontStyle.italic : null, + color: widget.color!=null ? widget.color : Colors.black, + fontSize: _getFontSize(), + letterSpacing: widget.variant=="overline" ? 1.5 : null, + fontWeight: _getFontWeight(), + ) + ), + if (widget.readMore && text.length > widget.maxLength && hidden) + Positioned( + bottom: 0, + left: 0, + right: 0, + child: Container( + decoration: BoxDecoration( + gradient: LinearGradient( + colors: [ + Theme.of(context).backgroundColor, + Theme.of(context).backgroundColor.withOpacity(0), + ], + begin: Alignment.bottomCenter, + end: Alignment.topCenter + ) + ), + height: 30, + ), + ) + ], + ), + if (widget.allowExpand && widget.readMore && text.length > widget.maxLength) + Padding( + padding: EdgeInsets.only(top: 8.0, right: 8.0, bottom: 8.0), + child: InkWell( + onTap: () { + setState(() { + hidden=!hidden; + }); + }, + child: Text(hidden ? "Read More" : "Read less", + style: _getFontStyle().copyWith( + color: Hexcolor('#515b5d'), + fontWeight: FontWeight.w800, + fontFamily: "WorkSans" + ) + ), + ), + ), + ], + ); + } +} diff --git a/lib/widgets/shared/TextFields.dart b/lib/widgets/shared/TextFields.dart new file mode 100644 index 00000000..269ad660 --- /dev/null +++ b/lib/widgets/shared/TextFields.dart @@ -0,0 +1,185 @@ +import 'package:eva_icons_flutter/eva_icons_flutter.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; + + + +class TextFields extends StatefulWidget { + + TextFields({Key key, this.type, this.hintText, this.suffixIcon, this.autoFocus, this.onChanged, this.initialValue, this.minLines, this.maxLines, this.inputFormatters, this.padding, this.focus=false, this.maxLengthEnforced=true, + this.suffixIconColor, this.inputAction, this.onSubmit, this.keepPadding=true, this.textCapitalization = TextCapitalization.none, this.onTap, this.controller, this.keyboardType, this.validator, this.borderOnlyError=false, + this.onSaved, this.onSuffixTap, this.readOnly: false, this.maxLength, this.prefixIcon, this.bare=false, this.fontSize=16.0, this.fontWeight=FontWeight.w700, this.autoValidate=false}) : super(key: key); + + final String hintText; + final String initialValue; + final String type; + final bool autoFocus; + final IconData suffixIcon; + final Color suffixIconColor; + final IconData prefixIcon; + final VoidCallback onTap; + final TextEditingController controller; + final TextInputType keyboardType; + final FormFieldValidator validator; + final Function onSaved; + final Function onSuffixTap; + final Function onChanged; + final Function onSubmit; + final bool readOnly; + final int maxLength; + final int minLines; + final int maxLines; + final bool maxLengthEnforced; + final bool bare; + final TextInputAction inputAction; + final double fontSize; + final FontWeight fontWeight; + final bool keepPadding; + final TextCapitalization textCapitalization; + final List inputFormatters; + final bool autoValidate; + final EdgeInsets padding; + final bool focus; + final bool borderOnlyError; + + @override + _TextFieldsState createState() => _TextFieldsState(); +} + +class _TextFieldsState extends State { + final FocusNode _focusNode = FocusNode(); + bool focus = false; + bool view = false; + + @override + void initState() { + super.initState(); + _focusNode.addListener(() { + setState(() { + focus = _focusNode.hasFocus; + }); + }); + } + + @override + void didUpdateWidget(TextFields oldWidget) { + if (widget.focus) + _focusNode.requestFocus(); + super.didUpdateWidget(oldWidget); + } + + @override + void dispose() { + _focusNode.dispose(); + super.dispose(); + } + + Widget _buildSuffixIcon() { + switch (widget.type) { + case "password": + { return Padding( + padding: const EdgeInsets.only(right: 8.0), + child: view ? + InkWell(onTap: () {this.setState(() { view= false; });}, child: Icon(EvaIcons.eye, size: 24.0, color: Color.fromRGBO(78, 62, 253, 1.0))) + : + InkWell(onTap: () {this.setState(() { view= true; });}, child: Icon(EvaIcons.eyeOff, size: 24.0, color: Colors.grey[500])) + );} + + break; + default: + if (widget.suffixIcon!=null) + return InkWell(onTap: widget.onSuffixTap, child: Icon(widget.suffixIcon, size: 22.0, color: widget.suffixIconColor!=null ? widget.suffixIconColor : Colors.grey[500])); + else + return null; + } + } + + bool _determineReadOnly() { + if (widget.readOnly!=null && widget.readOnly) { + _focusNode.unfocus(); + return true; + } else { + return false; + } + } + + @override + Widget build(BuildContext context) { + return ( + AnimatedContainer( + duration: Duration(milliseconds: 300), + decoration: widget.bare ? null :BoxDecoration( + boxShadow: [BoxShadow(color: Color.fromRGBO(70, 68, 167, focus ? 0.20 : 0), offset: Offset(0.0, 13.0), blurRadius: focus ? 34.0 : 12.0)] + ), + child: TextFormField( + keyboardAppearance: Theme.of(context).brightness, + scrollPhysics: BouncingScrollPhysics(), + autovalidate: widget.autoValidate, + textCapitalization: widget.textCapitalization, + onFieldSubmitted: widget.inputAction==TextInputAction.next ? (widget.onSubmit!=null ? widget.onSubmit : (val) { _focusNode.nextFocus(); }) : widget.onSubmit, + textInputAction: widget.inputAction, + minLines: widget.minLines ?? 1, + maxLines: widget.maxLines ?? 1, + maxLengthEnforced: widget.maxLengthEnforced, + initialValue: widget.initialValue, + onChanged: widget.onChanged, + focusNode: _focusNode, + maxLength: widget.maxLength ?? null, + controller: widget.controller, + keyboardType: widget.keyboardType, + readOnly: _determineReadOnly(), + obscureText: widget.type=="password" && !view ? true : false, + autofocus: widget.autoFocus ?? false, + validator: widget.validator, + onSaved: widget.onSaved, + style: Theme.of(context).textTheme.body2.copyWith( fontSize: widget.fontSize, fontWeight: widget.fontWeight ), + inputFormatters: widget.inputFormatters, + decoration: InputDecoration( + counterText: "", + hintText: widget.hintText, + hintStyle: TextStyle(fontSize: widget.fontSize, fontWeight: widget.fontWeight, color: Theme.of(context).hintColor), + + contentPadding: widget.padding!=null ? widget.padding : EdgeInsets.symmetric(vertical: (widget.bare && !widget.keepPadding) ? 0.0 : 10.0, horizontal: 16.0), + filled: true, + fillColor: widget.bare ? Colors.transparent : Theme.of(context).backgroundColor, + + suffixIcon: _buildSuffixIcon(), + prefixIcon: widget.type!="search" ? + widget.prefixIcon!=null ? + Padding( + padding: EdgeInsets.only(left: 28.0, top: 14.0, bottom: 14.0, right: 0), + child: Text("\$", style: TextStyle( fontSize: 14, fontWeight: FontWeight.w800),), + ) + : + null + : + Icon(EvaIcons.search, size: 20.0, color: Colors.grey[500]), + + errorStyle: TextStyle(fontSize: 14.0, fontWeight: widget.fontWeight, height: widget.borderOnlyError ? 0.0 : null), + errorBorder: OutlineInputBorder( + borderSide: BorderSide(color: Theme.of(context).errorColor.withOpacity(widget.bare ? 0.0 : 0.5 ), width: 2.0), + borderRadius: BorderRadius.circular(widget.bare ? 0.0 : 8.0) + ), + focusedErrorBorder: OutlineInputBorder( + borderSide: BorderSide(color: Theme.of(context).errorColor.withOpacity(widget.bare ? 0.0 : 0.5 ), width: 2.0), + borderRadius: BorderRadius.circular(widget.bare ? 0.0 : 8.0) + ), + focusedBorder: OutlineInputBorder( + borderSide: BorderSide(color: Theme.of(context).dividerColor.withOpacity(widget.bare ? 0.0 : 1.0 ), width: 2.0), + borderRadius: BorderRadius.circular(widget.bare ? 0.0 : 8.0) + ), + disabledBorder: OutlineInputBorder( + borderSide: BorderSide(color: Theme.of(context).dividerColor.withOpacity(widget.bare ? 0.0 : 1.0 ), width: 2.0), + borderRadius: BorderRadius.circular(widget.bare ? 0.0 : 8.0) + ), + enabledBorder: OutlineInputBorder( + borderSide: BorderSide(color: Theme.of(context).dividerColor.withOpacity(widget.bare ? 0.0 : 1.0 ), width: 2.0), + borderRadius: BorderRadius.circular(widget.bare ? 0.0 : 8.0) + ) + + ), + ), + ) + ); + } +} diff --git a/lib/widgets/shared/app_button.dart b/lib/widgets/shared/app_button.dart index 522255df..32f5b139 100644 --- a/lib/widgets/shared/app_button.dart +++ b/lib/widgets/shared/app_button.dart @@ -86,8 +86,7 @@ class _ButtonState extends State