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.
diplomatic-quarter/lib/vital_signs/components/vital_sign_widget.dart

377 lines
14 KiB
Dart

import 'package:diplomaticquarterapp/theme/colors.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/uitl/utils_new.dart';
import 'package:diplomaticquarterapp/vital_signs/data/vitals_benchmark.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
class VitalSignWidget extends StatelessWidget {
final String vitalSignName;
final String vitalSignValue;
final String vectorUrl;
final dynamic condition;
final Map<String, dynamic>? lookupValues;
final Map<String, dynamic>? bloodPressureValues;
final Color? textColor;
const VitalSignWidget({
Key? key,
required this.vitalSignName,
required this.vitalSignValue,
this.textColor,
required this.condition,
required this.vectorUrl,
this.lookupValues,
this.bloodPressureValues,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return Card(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
color: Colors.white,
elevation: 2,
shadowColor: CustomColors.lightGreyColor,
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Column(crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, children: [
Row(
children: [
SvgPicture.asset(vectorUrl, width: 36.0, height: 36.0),
SizedBox(
width: 16,
),
Text(
vitalSignName,
textAlign: TextAlign.start,
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.w600,
color: textColor ?? Colors.white,
),
),
],
),
SizedBox(
height: 8,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"$vitalSignValue ${condition.unit}",
style: TextStyle(
fontSize: 14,
color: textColor ?? Colors.white,
fontWeight: FontWeight.w500,
),
),
SizedBox(
width: 8,
),
if (condition is RangeConditionWithTitle)
Status(
status: "${TranslationBase.of(context).getValue(condition.current?.interpretation ?? '')}",
originalData: condition.current?.interpretation ?? '',
)
else if (condition is RangeConditionForBloodPressure)
Status(
status: "${TranslationBase.of(context).getValue(condition.systolic?.systolic.interpretation ?? '')}",
originalData: condition.systolic?.systolic.interpretation ?? '',
)
// Text(
// "${TranslationBase.of(context).getValue(condition.current?.quantitativeInterpretation ?? '')}",
// style: TextStyle(
// fontSize: 14,
// color: textColor ?? Colors.white,
// fontWeight: FontWeight.w500,
// ),
// ),
],
),
SizedBox(
height: 8,
),
// SizedBox(
// height: 30,
// child: Row(mainAxisSize: MainAxisSize.max, children: [
if (condition is RangeConditionWithTitle)
SizedBox(
height: 30,
child: Row(mainAxisSize: MainAxisSize.max, children: [
Expanded(
flex: 1,
child: ListView.separated(
separatorBuilder: (_, __) => SizedBox(
width: 8,
),
scrollDirection: Axis.horizontal,
shrinkWrap: true,
itemCount: condition.condition?.length ?? 0,
itemBuilder: (_, index) => RangeWidget(
title: condition.condition?[index].title ?? 'test',
isSelected: condition.condition?[index].isInRange(vitalSignValue) == true,
originalData: condition.current?.interpretation ?? '',
),
),
),
]),
),
// Flexible(
// flex: 1,
// child: ListView.separated(
// physics: NeverScrollableScrollPhysics(),
// separatorBuilder: (_, __) => SizedBox(
// width: 8,
// ),
// shrinkWrap: true,
// itemCount: lookupValues?.length ?? 0,
// itemBuilder: (_, index) {
// var key = lookupValues?.keys.elementAt(index);
// return RangeWidget(
// title: key ?? '',
// values: lookupValues?[key] ?? [],
// isSelected: false,
// );
// }),
// ),
if (condition is RangeConditionForBloodPressure)
SizedBox(
height: 30,
child: Row(mainAxisSize: MainAxisSize.max, children: [
Expanded(
flex: 1,
child: ListView.separated(
separatorBuilder: (_, __) => SizedBox(
width: 8,
),
scrollDirection: Axis.horizontal,
shrinkWrap: true,
itemCount: condition.condition?.length ?? 0,
itemBuilder: (_, currentIndex) {
var title = condition.condition?[currentIndex].quotient ?? '';
return RangeWidget(
title: title,
isSelected: condition.condition?[currentIndex]?.getValue("systolic-lng")?.isSelected == true,
originalData: condition.systolic?.systolic.interpretation ?? '',
);
}),
),
]),
),
// Flexible(
// flex: 1,
// child: ListView.separated(
// separatorBuilder: (_, __) => SizedBox(
// width: 8,
// ),
// physics: NeverScrollableScrollPhysics(),
// shrinkWrap: true,
// itemCount: bloodPressure.length ?? 0,
// itemBuilder: (_, index) {
// // return RangeWidget(
// // title: key??'',
// // values: lookupValues?[key]??[],isSelected: false,
// // );
// return Column(
// children: [
// Row(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
// children: [
// Text(
// TranslationBase.of(context)
// .getValue(bloodPressure[index] ?? ''),
// textAlign: TextAlign.center,
// style:
// TextStyle(color: Colors.black, fontSize: 16),
// ),
//
// Status(
// status:
// "${TranslationBase.of(context).getValue(condition.getValue(bloodPressure[index])?.quantitativeInterpretation ?? '')}",
// originalData:condition.getValue(bloodPressure[index])?.quantitativeInterpretation ?? '' ,
// )
// ],
// ),
// SizedBox(height: 16),
// SizedBox(
// height: 30,
// child: Row(
// mainAxisSize: MainAxisSize.max,
// children: [
// Expanded(
// flex: 1,
// child: ListView.separated(
// separatorBuilder: (_, __) => SizedBox(
// width: 8,
// ),
// scrollDirection: Axis.horizontal,
// shrinkWrap: true,
// itemCount:
// condition.condition?.length ?? 0,
// itemBuilder: (_, currentIndex) {
// var title = condition
// .condition?[currentIndex]
// .getValue(
// bloodPressure[index]).title ??
// '';
// return RangeWidget(
// title: title,
// isSelected: condition
// .condition?[currentIndex]
// ?.getValue(
// bloodPressure[index])
// ?.isSelected ==
// true,
// );
// }),
// ),
// ]),
// ),
// SizedBox(height: 16),
// // SizedBox(
// // height:220,
// // child: ListView.separated(
// // separatorBuilder: (_, __) => SizedBox(
// // width: 8,
// // ),
// // physics: NeverScrollableScrollPhysics(),
// // shrinkWrap: true,
// // itemCount: bloodPressureValues?[key]?.length ?? 0,
// // itemBuilder: (_, index) {
// // var title = bloodPressureValues?[key]?.keys.elementAt(index);
// //
// // return RangeWidget(
// // title: title ?? '',
// // values: bloodPressureValues?[key]?[title] ?? [],
// // isSelected: false,
// // );
// // }))
// ],
// );
// }),
// ),
// ]),
// ),
SizedBox(
height: 8,
),
// Row(
// mainAxisAlignment: MainAxisAlignment.spaceBetween,
// children: [
// Text(
// TranslationBase.of(context).getValue(
// condition.condition?.first.interpretation ?? ''),
// style: TextStyle(
// fontSize: 14,
// color: textColor ?? Colors.white,
// fontWeight: FontWeight.w500,
// ),
// ),
// Text(
// TranslationBase.of(context).getValue(
// condition.condition?.last.interpretation ?? ''),
// style: TextStyle(
// fontSize: 14,
// color: textColor ?? Colors.white,
// fontWeight: FontWeight.w500,
// ),
// ),
// ],
// ),
// SizedBox(
// height: 8,
// ),
]),
),
);
}
}
class RangeWidget extends StatelessWidget {
final String title;
final bool isSelected;
final String originalData;
const RangeWidget({super.key, required this.title, required this.isSelected, required this.originalData});
@override
Widget build(BuildContext context) {
return SizedBox(
height: 30,
child: Material(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(3),
),
// color: Color(0xFF359846),
color: (isSelected) ? getColor(originalData) : CustomColors.lightGreyColor,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Center(
child: Text(
title,
textAlign: TextAlign.center,
style: TextStyle(color: (isSelected) ? Colors.white : Colors.black, fontSize: 12),
),
),
),
),
);
}
getColor(title) {
switch (title) {
case "excellent":
return Color(0xFF275b45);
case "good":
return Color(0xFF507a3d);
case "poor":
return Color(0xFFa86452);
case "atRisk":
return Color(0xFFa2494b);
}
}
}
class Status extends StatelessWidget {
final String status;
final String originalData;
const Status({super.key, required this.status, required this.originalData});
@override
Widget build(BuildContext context) {
return Material(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(3),
),
// color: Color(0xFF359846),
color: getColor(originalData),
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6),
child: Text(status,
style: TextStyle(
color: Colors.white,
fontSize: 12,
fontWeight: FontWeight.w600,
)),
));
}
getColor(title) {
switch (title) {
case "excellent":
return Color(0xFF275b45);
case "good":
return Color(0xFF507a3d);
case "poor":
return Color(0xFFa86452);
case "atRisk":
return Color(0xFFa2494b);
}
}
}