DA-250: fix age

merge-requests/275/head
Elham Rababah 5 years ago
parent 81fdcb2d8d
commit 13c879654b

@ -17,6 +17,7 @@ import 'package:doctor_app_flutter/models/patient/patient_model.dart';
import 'package:doctor_app_flutter/models/patient/topten_users_res_model.dart';
import 'package:doctor_app_flutter/routes.dart';
import 'package:doctor_app_flutter/screens/base/base_view.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/shared/app_texts_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/dr_app_circular_progress_Indeicator.dart';
@ -615,9 +616,8 @@ class _PatientsScreenState extends State<PatientsScreen> {
.white,
),
AppText(
item
.age
.toString(),
" ${DateUtils.getAgeByBirthday(item.dateofBirth)}",
fontSize: 1.8 *
SizeConfig
.textMultiplier,

@ -216,5 +216,23 @@ class DateUtils {
return 12;
}
}
static String getAgeByBirthday(dynamic birthday){
// https://leechy.dev/calculate-dates-diff-in-dart
DateTime birthDate = DateUtils.getDateTimeFromServerFormat(birthday);
final now = DateTime.now();
int years = now.year - birthDate .year;
int months = now.month - birthDate.month;
int days = now.day - birthDate.day;
if (months < 0 || (months == 0 && days < 0)) {
years--;
months += (days < 0 ? 11 : 12);
}
if (days < 0) {
final monthAgo = new DateTime(now.year, now.month - 1, birthDate.day);
days = now.difference(monthAgo).inDays + 1;
}
return "$years Yr $months Mnth $days Day";
}
}

@ -18,23 +18,7 @@ import './profile_medical_info_widget.dart';
class PatientProfileWidget extends StatelessWidget {
PatiantInformtion patient;
String getPatientAge(dynamic birthday){
// https://leechy.dev/calculate-dates-diff-in-dart
DateTime birthDate = DateUtils.getDateTimeFromServerFormat(birthday);
final now = DateTime.now();
int years = now.year - birthDate .year;
int months = now.month - birthDate.month;
int days = now.day - birthDate.day;
if (months < 0 || (months == 0 && days < 0)) {
years--;
months += (days < 0 ? 11 : 12);
}
if (days < 0) {
final monthAgo = new DateTime(now.year, now.month - 1, birthDate.day);
days = now.difference(monthAgo).inDays + 1;
}
return "$years Yr $months Mnth $days Day";
}
@override
Widget build(BuildContext context) {
@ -133,7 +117,7 @@ class PatientProfileWidget extends StatelessWidget {
height: 4,
),
AppText(
"${DateUtils.convertDateFromServerFormat(patient.dateofBirth, 'dd-MM-yyyy')} / ${getPatientAge(patient.dateofBirth)/*patient.age*/}",
"${DateUtils.convertDateFromServerFormat(patient.dateofBirth, 'dd-MM-yyyy')} / ${DateUtils.getAgeByBirthday(patient.dateofBirth)/*patient.age*/}",
fontWeight: FontWeight.normal,
fontSize: 1.6 * SizeConfig.textMultiplier,
),

Loading…
Cancel
Save