prescription refactoring

merge-requests/714/head
hussam al-habibeh 5 years ago
parent 764578f28e
commit da45f8c4b6

File diff suppressed because it is too large Load Diff

@ -0,0 +1,76 @@
import 'package:doctor_app_flutter/core/viewModel/medicine_view_model.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/dialogs/dailog-list-select.dart';
import 'package:doctor_app_flutter/widgets/shared/text_fields/app-textfield-custom.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
class PrescriptionTextFiled extends StatefulWidget {
dynamic element;
final String elementError;
final List<dynamic> elementList;
final String keyName;
final String keyId;
final String hintText;
final double width;
final Function(dynamic) okFunction;
PrescriptionTextFiled(
{Key key,
@required this.element,
@required this.elementError,
this.width,
this.elementList,
this.keyName,
this.keyId,
this.hintText,
this.okFunction})
: super(key: key);
@override
_PrescriptionTextFiledState createState() => _PrescriptionTextFiledState();
}
class _PrescriptionTextFiledState extends State<PrescriptionTextFiled> {
@override
Widget build(BuildContext context) {
return Container(
width: widget.width ?? null,
child: InkWell(
onTap: widget.elementList != null
? () {
Helpers.hideKeyboard(context);
ListSelectDialog dialog = ListSelectDialog(
list: widget.elementList,
attributeName: '${widget.keyName}',
attributeValueId: '${widget.keyId}',
okText: TranslationBase.of(context).ok,
okFunction: (selectedValue) =>
widget.okFunction(selectedValue),
);
showDialog(
barrierDismissible: false,
context: context,
builder: (BuildContext context) {
return dialog;
},
);
}
: null,
child: AppTextFieldCustom(
hintText: widget.hintText,
dropDownText: widget.elementList.length == 1
? widget.elementList[0]['${widget.keyName}']
: widget.element != null
? widget.element['${widget.keyName}']
: null,
isTextFieldHasSuffix: true,
validationError:
widget.elementList.length != 1 ? widget.elementError : null,
enabled: false,
),
),
);
}
}

@ -1,5 +1,4 @@
import 'package:doctor_app_flutter/core/viewModel/prescription_view_model.dart'; import 'package:doctor_app_flutter/core/viewModel/prescription_view_model.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/models/patient/patiant_info_model.dart';
import 'package:doctor_app_flutter/screens/base/base_view.dart'; import 'package:doctor_app_flutter/screens/base/base_view.dart';
import 'package:doctor_app_flutter/screens/prescription/add_prescription_form.dart'; import 'package:doctor_app_flutter/screens/prescription/add_prescription_form.dart';
@ -16,7 +15,6 @@ import 'package:doctor_app_flutter/widgets/shared/user-guid/in_patient_doctor_ca
import 'package:doctor_app_flutter/widgets/transitions/fade_page.dart'; import 'package:doctor_app_flutter/widgets/transitions/fade_page.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
class PrescriptionsPage extends StatelessWidget { class PrescriptionsPage extends StatelessWidget {
@override @override
@ -86,9 +84,7 @@ class PrescriptionsPage extends StatelessWidget {
fontSize: 13, fontSize: 13,
), ),
AppText( AppText(
TranslationBase TranslationBase.of(context).prescriptions,
.of(context)
.prescriptions,
bold: true, bold: true,
fontSize: 22, fontSize: 22,
), ),
@ -103,8 +99,7 @@ class PrescriptionsPage extends StatelessWidget {
addPrescriptionForm(context, model, patient, addPrescriptionForm(context, model, patient,
model.prescriptionList); model.prescriptionList);
}, },
label: TranslationBase label: TranslationBase.of(context)
.of(context)
.applyForNewPrescriptionsOrder, .applyForNewPrescriptionsOrder,
), ),
...List.generate( ...List.generate(

@ -7,7 +7,7 @@ class AppDateUtils {
return DateFormat(dateFormat).format(dateTime); return DateFormat(dateFormat).format(dateTime);
} }
static DateTime convertISOStringToDateTime(String date){ static DateTime convertISOStringToDateTime(String date) {
DateTime newDate; DateTime newDate;
newDate = DateTime.parse(date); newDate = DateTime.parse(date);
@ -27,22 +27,20 @@ class AppDateUtils {
} }
static DateTime getDateTimeFromServerFormat(String str) { static DateTime getDateTimeFromServerFormat(String str) {
DateTime date= DateTime.now(); DateTime date = DateTime.now();
if (str!=null) { if (str != null) {
const start = "/Date("; const start = "/Date(";
const end = "+0300)"; const end = "+0300)";
if(str.contains("/Date")){ if (str.contains("/Date")) {
final startIndex = str.indexOf(start); final startIndex = str.indexOf(start);
final endIndex = str.indexOf(end, startIndex + start.length); final endIndex = str.indexOf(end, startIndex + start.length);
date = new DateTime.fromMillisecondsSinceEpoch( date = new DateTime.fromMillisecondsSinceEpoch(int.parse(str.substring(startIndex + start.length, endIndex)));
int.parse(str.substring(startIndex + start.length, endIndex)));
} else { } else {
date = DateTime.now(); date = DateTime.now();
} }
} else { } else {
date = DateTime.parse(str); date = DateTime.parse(str);
} }
@ -50,8 +48,7 @@ class AppDateUtils {
return date; return date;
} }
static String differenceBetweenDateAndCurrentInYearMonthDay( static String differenceBetweenDateAndCurrentInYearMonthDay(DateTime firstDate, BuildContext context) {
DateTime firstDate, BuildContext context) {
DateTime now = DateTime.now(); DateTime now = DateTime.now();
// now = now.add(Duration(days: 400, minutes: 0)); // now = now.add(Duration(days: 400, minutes: 0));
var difference = firstDate.difference(now); var difference = firstDate.difference(now);
@ -71,15 +68,13 @@ class AppDateUtils {
return "$days ${TranslationBase.of(context).days}, $months ${TranslationBase.of(context).months}, $years ${TranslationBase.of(context).years}"; return "$days ${TranslationBase.of(context).days}, $months ${TranslationBase.of(context).months}, $years ${TranslationBase.of(context).years}";
} }
static String differenceBetweenDateAndCurrent( static String differenceBetweenDateAndCurrent(DateTime firstDate, BuildContext context) {
DateTime firstDate, BuildContext context) {
DateTime now = DateTime.now(); DateTime now = DateTime.now();
// DateTime now = nows.add(Duration(days: 400, minutes: 25, hours: 0)); // DateTime now = nows.add(Duration(days: 400, minutes: 25, hours: 0));
var difference = now.difference(firstDate); var difference = now.difference(firstDate);
int minutesInDays = difference.inMinutes; int minutesInDays = difference.inMinutes;
int hoursInDays = int hoursInDays = minutesInDays ~/ 60; // ~/ : truncating division to make the result int
minutesInDays ~/ 60; // ~/ : truncating division to make the result int
int minutes = minutesInDays % 60; int minutes = minutesInDays % 60;
int days = hoursInDays ~/ 24; int days = hoursInDays ~/ 24;
int hours = hoursInDays % 24; int hours = hoursInDays % 24;
@ -89,8 +84,7 @@ class AppDateUtils {
return "$days ${TranslationBase.of(context).days}, $hours ${TranslationBase.of(context).hr}, $minutes ${TranslationBase.of(context).min}"; return "$days ${TranslationBase.of(context).days}, $hours ${TranslationBase.of(context).hr}, $minutes ${TranslationBase.of(context).min}";
} }
static String differenceBetweenServerDateAndCurrent( static String differenceBetweenServerDateAndCurrent(String str, BuildContext context) {
String str, BuildContext context) {
const start = "/Date("; const start = "/Date(";
const end = "+0300)"; const end = "+0300)";
@ -99,8 +93,7 @@ class AppDateUtils {
final endIndex = str.indexOf(end, startIndex + start.length); final endIndex = str.indexOf(end, startIndex + start.length);
var date = new DateTime.fromMillisecondsSinceEpoch( var date = new DateTime.fromMillisecondsSinceEpoch(int.parse(str.substring(startIndex + start.length, endIndex)));
int.parse(str.substring(startIndex + start.length, endIndex)));
return differenceBetweenDateAndCurrent(date, context); return differenceBetweenDateAndCurrent(date, context);
} }
@ -246,7 +239,10 @@ class AppDateUtils {
final startIndex = date.indexOf(start); final startIndex = date.indexOf(start);
final endIndex = date.indexOf(end, startIndex + start.length); final endIndex = date.indexOf(end, startIndex + start.length);
DateTime newDate = DateTime.fromMillisecondsSinceEpoch( DateTime newDate = DateTime.fromMillisecondsSinceEpoch(
int.parse(date.substring(startIndex + start.length, endIndex),),); int.parse(
date.substring(startIndex + start.length, endIndex),
),
);
return newDate; return newDate;
} else } else
return DateTime.now(); return DateTime.now();
@ -256,35 +252,30 @@ class AppDateUtils {
/// [dateTime] convert DateTime to data formatted Arabic /// [dateTime] convert DateTime to data formatted Arabic
static String getMonthDayYearDateFormattedAr(DateTime dateTime) { static String getMonthDayYearDateFormattedAr(DateTime dateTime) {
if (dateTime != null) if (dateTime != null)
return getMonthArabic(dateTime.month) + return getMonthArabic(dateTime.month) + " " + dateTime.day.toString() + ", " + dateTime.year.toString();
" " +
dateTime.day.toString() +
", " +
dateTime.year.toString();
else else
return ""; return "";
} }
/// get data formatted like Apr 26,2020 /// get data formatted like Apr 26,2020
/// [dateTime] convert DateTime to data formatted /// [dateTime] convert DateTime to data formatted
static String getMonthDayYearDateFormatted(DateTime dateTime,{bool isArabic = false}) { static String getMonthDayYearDateFormatted(DateTime dateTime, {bool isArabic = false}) {
if (dateTime != null) if (dateTime != null)
return isArabic? getMonthArabic(dateTime.month): getMonth(dateTime.month) + return isArabic
" " + ? getMonthArabic(dateTime.month)
dateTime.day.toString() + : getMonth(dateTime.month) + " " + dateTime.day.toString() + ", " + dateTime.year.toString();
", " +
dateTime.year.toString();
else else
return ""; return "";
} }
/// get data formatted like 26 Apr 2020 /// get data formatted like 26 Apr 2020
/// [dateTime] convert DateTime to data formatted /// [dateTime] convert DateTime to data formatted
static String getDayMonthYearDateFormatted(DateTime dateTime,{bool isArabic = false}) { static String getDayMonthYearDateFormatted(DateTime dateTime, {bool isArabic = false}) {
if (dateTime != null) if (dateTime != null)
return dateTime.day.toString()+" "+ "${isArabic? getMonthArabic(dateTime.month): getMonth(dateTime.month) }"+ return dateTime.day.toString() +
" " +
"${isArabic ? getMonthArabic(dateTime.month) : getMonth(dateTime.month)}" +
" " + " " +
dateTime.year.toString(); dateTime.year.toString();
else else
return ""; return "";
@ -292,9 +283,9 @@ class AppDateUtils {
/// get data formatted like 26/4/2020 /// get data formatted like 26/4/2020
/// [dateTime] convert DateTime to data formatted /// [dateTime] convert DateTime to data formatted
static String getDayMonthYearDate(DateTime dateTime,{bool isArabic = false}) { static String getDayMonthYearDate(DateTime dateTime, {bool isArabic = false}) {
if (dateTime != null) if (dateTime != null)
return dateTime.day.toString()+"/"+ "${dateTime.month}"+ "/" + dateTime.year.toString(); return dateTime.day.toString() + "/" + "${dateTime.month}" + "/" + dateTime.year.toString();
else else
return ""; return "";
} }
@ -305,12 +296,12 @@ class AppDateUtils {
return DateFormat('hh:mm a').format(dateTime); return DateFormat('hh:mm a').format(dateTime);
} }
static String getAgeByBirthday(String birthOfDate, BuildContext context, { bool isServerFormat = true}) { static String getAgeByBirthday(String birthOfDate, BuildContext context, {bool isServerFormat = true}) {
// https://leechy.dev/calculate-dates-diff-in-dart // https://leechy.dev/calculate-dates-diff-in-dart
DateTime birthDate; DateTime birthDate;
if(birthOfDate.contains("/Date")) { if (birthOfDate.contains("/Date")) {
birthDate = AppDateUtils.getDateTimeFromServerFormat(birthOfDate); birthDate = AppDateUtils.getDateTimeFromServerFormat(birthOfDate);
}else{ } else {
birthDate = DateTime.parse(birthOfDate); birthDate = DateTime.parse(birthOfDate);
} }
final now = DateTime.now(); final now = DateTime.now();
@ -328,24 +319,18 @@ class AppDateUtils {
return "$years ${TranslationBase.of(context).years} $months ${TranslationBase.of(context).months} $days ${TranslationBase.of(context).days}"; return "$years ${TranslationBase.of(context).years} $months ${TranslationBase.of(context).months} $days ${TranslationBase.of(context).days}";
} }
static bool isToday(DateTime dateTime){ static bool isToday(DateTime dateTime) {
DateTime todayDate = DateTime.now().toUtc(); DateTime todayDate = DateTime.now().toUtc();
if(dateTime.day == todayDate.day && dateTime.month == todayDate.month && dateTime.year == todayDate.year) { if (dateTime.day == todayDate.day && dateTime.month == todayDate.month && dateTime.year == todayDate.year) {
return true; return true;
} }
return false; return false;
} }
static String getDate(DateTime dateTime) { static String getDate(DateTime dateTime) {
print(dateTime); print(dateTime);
if (dateTime != null) if (dateTime != null)
return getMonth(dateTime.month) + return getMonth(dateTime.month) + " " + dateTime.day.toString() + "," + dateTime.year.toString();
" " +
dateTime.day.toString() +
"," +
dateTime.year.toString();
else else
return ""; return "";
} }
@ -353,28 +338,23 @@ class AppDateUtils {
static String getDateFormatted(DateTime dateTime) { static String getDateFormatted(DateTime dateTime) {
print(dateTime); print(dateTime);
if (dateTime != null) if (dateTime != null)
return dateTime.day.toString() + return dateTime.day.toString() + "/" + dateTime.month.toString() + "/" + dateTime.year.toString();
"/" +
dateTime.month.toString() +
"/" +
dateTime.year.toString();
else else
return ""; return "";
} }
static String getTimeHHMMA(DateTime dateTime){ static String getTimeHHMMA(DateTime dateTime) {
return DateFormat('hh:mm a').format(dateTime); return DateFormat('hh:mm a').format(dateTime);
} }
static String getTimeHHMMA2 (DateTime dateTime){ static String getTimeHHMMA2(DateTime dateTime) {
return DateFormat('hh:mm').format(dateTime); return DateFormat('hh:mm').format(dateTime);
} }
static String getStartTime(String dateTime){ static String getStartTime(String dateTime) {
String time=dateTime; String time = dateTime;
if(dateTime.length>7) if (dateTime.length > 7) time = dateTime.substring(0, 5);
time = dateTime.substring(0,5);
return time; return time;
} }

@ -134,8 +134,7 @@ class _AppTextFieldCustomState extends State<AppTextFieldCustom> {
widget.onChanged(value); widget.onChanged(value);
} }
}, },
obscureText: widget.isSecure obscureText: widget.isSecure),
),
) )
: AppText( : AppText(
widget.dropDownText, widget.dropDownText,

@ -12,7 +12,6 @@ class TextFieldsError extends StatelessWidget {
final String error; final String error;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
@ -27,13 +26,15 @@ class TextFieldsError extends StatelessWidget {
SizedBox( SizedBox(
width: 12, width: 12,
), ),
AppText( Expanded(
child: AppText(
error, error,
fontFamily: 'Poppins', fontFamily: 'Poppins',
fontSize: SizeConfig.textMultiplier * 1.7, fontSize: SizeConfig.textMultiplier * 1.7,
color: Colors.red.shade700, color: Colors.red.shade700,
fontWeight: FontWeight.w700, fontWeight: FontWeight.w700,
), ),
),
], ],
), ),
); );

Loading…
Cancel
Save