diff --git a/lib/pages/AlHabibMedicalService/all_habib_medical_service_page.dart b/lib/pages/AlHabibMedicalService/all_habib_medical_service_page.dart index 616b5fd8..6854cb27 100644 --- a/lib/pages/AlHabibMedicalService/all_habib_medical_service_page.dart +++ b/lib/pages/AlHabibMedicalService/all_habib_medical_service_page.dart @@ -226,8 +226,8 @@ class _AllHabibMedicalServiceState extends State { onTap: () => Navigator.push( context, FadePage( - //page: HealthConverter(), - ), + page: HealthConverter(), + ), ), imageLocation: 'assets/images/new-design/health_convertor_icon.png', diff --git a/lib/pages/AlHabibMedicalService/health_converter.dart b/lib/pages/AlHabibMedicalService/health_converter.dart index b499724c..61ea406f 100644 --- a/lib/pages/AlHabibMedicalService/health_converter.dart +++ b/lib/pages/AlHabibMedicalService/health_converter.dart @@ -1,94 +1,96 @@ -// import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; -// import 'package:diplomaticquarterapp/widgets/data_display/medical/medical_profile_item.dart'; -// import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; -// import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart'; -// import 'package:flutter/material.dart'; -// -// import 'health_converter/blood_sugar.dart'; -// -// class HealthConverter extends StatefulWidget { -// @override -// _HealthConverterState createState() => _HealthConverterState(); -// } -// -// class _HealthConverterState extends State { -// @override -// Widget build(BuildContext context) { -// return AppScaffold( -// isShowAppBar: true, -// appBarTitle: 'Health Converter', -// body: Column( -// children: [ -// Container( -// width: double.infinity, -// height: 30, -// ), -// Row( -// children: [ -// Expanded( -// flex: 1, -// child: InkWell( -// onTap: () { -// Navigator.push( -// context, -// FadePage(page: BloodSugar()), -// ); -// }, -// child: MedicalProfileItem( -// title: 'Blood', -// imagePath: 'blood_sugar_icon.png', -// subTitle: 'Sugar', -// ), -// ), -// ), -// Expanded( -// flex: 1, -// child: InkWell( -// onTap: () { -// Navigator.push( -// context, -// FadePage( -// // page: [](), -// ), -// ); -// }, -// child: MedicalProfileItem( -// title: 'Blood', -// imagePath: 'blood_cholesterol_icon.png', -// subTitle: 'Cholesterol', -// ), -// ), -// ), -// ], -// ), -// Row( -// children: [ -// Expanded( -// flex: 1, -// child: InkWell( -// onTap: () { -// Navigator.push( -// context, -// FadePage( -// // page: [](), -// ), -// ); -// }, -// child: MedicalProfileItem( -// title: 'Triglycerides', -// imagePath: 'triglycerides_blood_icon.png', -// subTitle: 'Fat in blood', -// ), -// ), -// ), -// Expanded( -// flex: 1, -// child: Container(), -// ), -// ], -// ) -// ], -// ), -// ); -// } -// } +import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; +import 'package:diplomaticquarterapp/widgets/data_display/medical/medical_profile_item.dart'; +import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; +import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart'; +import 'package:flutter/material.dart'; + +import 'health_converter/blood_cholesterol.dart'; +import 'health_converter/blood_sugar.dart'; +import 'health_converter/triglycerides.dart'; + +class HealthConverter extends StatefulWidget { + @override + _HealthConverterState createState() => _HealthConverterState(); +} + +class _HealthConverterState extends State { + @override + Widget build(BuildContext context) { + return AppScaffold( + isShowAppBar: true, + appBarTitle: 'Health Converter', + body: Column( + children: [ + Container( + width: double.infinity, + height: 30, + ), + Row( + children: [ + Expanded( + flex: 1, + child: InkWell( + onTap: () { + Navigator.push( + context, + FadePage(page: BloodSugar()), + ); + }, + child: MedicalProfileItem( + title: 'Blood', + imagePath: 'blood_sugar_icon.png', + subTitle: 'Sugar', + ), + ), + ), + Expanded( + flex: 1, + child: InkWell( + onTap: () { + Navigator.push( + context, + FadePage( + page: BloodCholesterol(), + ), + ); + }, + child: MedicalProfileItem( + title: 'Blood', + imagePath: 'blood_cholesterol_icon.png', + subTitle: 'Cholesterol', + ), + ), + ), + ], + ), + Row( + children: [ + Expanded( + flex: 1, + child: InkWell( + onTap: () { + Navigator.push( + context, + FadePage( + page: Triglycerides(), + ), + ); + }, + child: MedicalProfileItem( + title: 'Triglycerides', + imagePath: 'triglycerides_blood_icon.png', + subTitle: 'Fat in blood', + ), + ), + ), + Expanded( + flex: 1, + child: Container(), + ), + ], + ) + ], + ), + ); + } +} diff --git a/lib/pages/AlHabibMedicalService/health_converter/blood_cholesterol.dart b/lib/pages/AlHabibMedicalService/health_converter/blood_cholesterol.dart new file mode 100644 index 00000000..7a48cf9b --- /dev/null +++ b/lib/pages/AlHabibMedicalService/health_converter/blood_cholesterol.dart @@ -0,0 +1,277 @@ +import 'package:flutter/material.dart'; +import 'package:diplomaticquarterapp/widgets/buttons/button.dart'; +import 'package:diplomaticquarterapp/widgets/buttons/secondary_button.dart'; +import 'package:diplomaticquarterapp/widgets/data_display/text.dart'; +import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; + +import 'package:flutter/services.dart'; + +const activeCardColor = Color(0xff70777A); +const inactiveCardColor = Color(0xffFAFAFd); + +class BloodCholesterol extends StatefulWidget { + @override + _BloodCholesterolState createState() => _BloodCholesterolState(); +} + +class _BloodCholesterolState extends State { + Color cardMGColor = inactiveCardColor; + Color cardMMOLColor = inactiveCardColor; + + void updateColor(int type) { + //MG/DLT card + if (type == 1) { + if (cardMGColor == inactiveCardColor) { + cardMGColor = activeCardColor; + cardMMOLColor = inactiveCardColor; + } else { + cardMGColor = inactiveCardColor; + } + } + if (type == 2) { + if (cardMMOLColor == inactiveCardColor) { + cardMMOLColor = activeCardColor; + cardMGColor = inactiveCardColor; + } else { + cardMMOLColor = inactiveCardColor; + } + } + } + + void calculateBloodCholesterol() { + if (cardMGColor == activeCardColor) { + inputValue = double.parse(textController.text); + inputValue = inputValue / conversionConst; + unit = 'mmol/l'; + } else if (cardMMOLColor == activeCardColor) { + inputValue = double.parse(textController.text); + inputValue = inputValue * conversionConst; + unit = 'mg/dlt'; + } + } + + bool _visible = false; + TextEditingController textController = new TextEditingController(); + String finalValue; + + double inputValue = 0.0; + String unit; + double conversionConst = 38.67; + + @override + Widget build(BuildContext context) { + return AppScaffold( + isShowAppBar: true, + appBarTitle: 'Blood Cholesterol ', + body: Padding( + padding: const EdgeInsets.all(16.0), + child: SingleChildScrollView( + child: Container( + height: MediaQuery.of(context).size.height * 0.7, + child: Column( + //crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Container( + width: 350.0, + child: Text( + 'Convert blood cholesterol from\n mmol/l to mg/dlt and vice versa.', + //textAlign: TextAlign.center, + style: TextStyle(fontSize: 20.0), + ), + ), + SizedBox( + height: 15.0, + ), + Container( + color: Colors.white, + height: 120.0, + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Column( + //crossAxisAlignment: CrossAxisAlignment.end, + children: [ + Padding( + padding: const EdgeInsets.symmetric(horizontal: 15.0), + child: Row( + children: [ + Texts( + 'Convert from', + ) + ], + ), + ), + SizedBox( + height: 9.0, + ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + GestureDetector( + onTap: () { + setState(() { + updateColor(1); + inputValue = + double.parse(textController.text); + inputValue = inputValue / conversionConst; + unit = 'mmol/l'; + }); + }, + child: Container( + height: 55.0, + width: 150.0, + decoration: BoxDecoration( + boxShadow: [ + BoxShadow( + color: Colors.grey.withOpacity(0.5), + spreadRadius: 3, + blurRadius: 7, + offset: Offset( + 0, 3), // changes position of shadow + ), + ], + color: cardMGColor, + borderRadius: BorderRadius.circular(3.0), + ), + child: Padding( + padding: const EdgeInsets.symmetric( + vertical: 0.0, horizontal: 18.0), + child: Texts('MG/DLt TO \nMMOL/L'), + ), + ), + ), + GestureDetector( + onTap: () { + setState(() { + updateColor(2); + inputValue = + double.parse(textController.text); + inputValue = inputValue * conversionConst; + unit = 'mg/dlt'; + }); + }, + child: Container( + height: 55.0, + width: 150.0, + decoration: BoxDecoration( + color: cardMMOLColor, + borderRadius: BorderRadius.circular(3.0), + boxShadow: [ + BoxShadow( + color: Colors.grey.withOpacity(0.5), + spreadRadius: 3, + blurRadius: 7, + offset: Offset( + 0, 3), // changes position of shadow + ), + ], + ), + child: Padding( + padding: const EdgeInsets.symmetric( + horizontal: 16.0), + child: Texts('MG/DLt TO\n MMOL/L'), + ), + ), + ), + ], + ), + ], + ), + ), + ), + SizedBox( + height: 25.0, + ), + Container( + height: 65.0, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(6.0), + color: Colors.white, + ), + child: TextFormField( + controller: textController, + inputFormatters: [ + FilteringTextInputFormatter.digitsOnly + ], + keyboardType: TextInputType.number, + decoration: InputDecoration( + border: OutlineInputBorder( + borderSide: BorderSide(color: Colors.black45)), + labelText: " Enter the reading value", + labelStyle: TextStyle( + color: Colors.black87, + ), + ), + ), + ), + SizedBox( + height: 25.0, + ), + Visibility( + visible: _visible, + child: Container( + height: 95.0, + width: 350.0, + decoration: BoxDecoration( + color: Colors.white, + border: Border.all(color: Colors.black), + borderRadius: BorderRadius.circular(15.0), + ), + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Texts('Result:'), + Row( + children: [ + Text( + inputValue.toStringAsFixed(3).toString(), + style: TextStyle(fontSize: 35.0), + ), + Padding( + padding: EdgeInsets.only(left: 4.0, top: 10.0), + child: Text( + unit.toString(), + style: TextStyle( + color: Color(0xffC5273A), + fontSize: 15.0, + fontWeight: FontWeight.w500, + ), + ), + ), + ], + ), + ], + ), + ), + ), + ), + SizedBox( + height: 15.0, + ), + Flexible( + child: Container( + height: 100.0, + width: 150.0, + child: Button( + label: 'CALCULATE', + onTap: () { + setState(() { + _visible == false + ? _visible = !_visible + : _visible = _visible; + calculateBloodCholesterol(); + }); + }, + ), + ), + ), + ], + ), + ), + ), + ), + ); + } +} diff --git a/lib/pages/AlHabibMedicalService/health_converter/blood_sugar.dart b/lib/pages/AlHabibMedicalService/health_converter/blood_sugar.dart index 654df11f..a90a5bbb 100644 --- a/lib/pages/AlHabibMedicalService/health_converter/blood_sugar.dart +++ b/lib/pages/AlHabibMedicalService/health_converter/blood_sugar.dart @@ -1,208 +1,279 @@ -// import 'package:diplomaticquarterapp/widgets/buttons/button.dart'; -// import 'package:diplomaticquarterapp/widgets/buttons/secondary_button.dart'; -// import 'package:diplomaticquarterapp/widgets/data_display/text.dart'; -// import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; -// import 'package:flutter/material.dart'; -// import 'package:flutter/services.dart'; -// -// const activeCardColor = Color(0xff70777A); -// const inactiveCardColor = Color(0xffFAFAFd); -// -// class BloodSugar extends StatefulWidget { -// @override -// _BloodSugarState createState() => _BloodSugarState(); -// } -// -// Color color; -// -// class _BloodSugarState extends State { -// Color cardMGColor = inactiveCardColor; -// Color cardMMOLColor = inactiveCardColor; -// -// void updateColor(int type) { -// //MG/DLT card -// if (type == 1) { -// if (cardMGColor == inactiveCardColor) { -// cardMGColor = activeCardColor; -// cardMMOLColor = inactiveCardColor; -// } else { -// cardMGColor = inactiveCardColor; -// } -// } -// if (type == 2) { -// if (cardMMOLColor == inactiveCardColor) { -// cardMMOLColor = activeCardColor; -// cardMGColor = inactiveCardColor; -// } else { -// cardMMOLColor = inactiveCardColor; -// } -// } -// } -// -// bool _visible = false; -// -// TextEditingController textController = new TextEditingController(); -// String finalValue; -// -// @override -// Widget build(BuildContext context) { -// return AppScaffold( -// isShowAppBar: true, -// appBarTitle: 'Blood Sugar Conversion', -// body: Padding( -// padding: const EdgeInsets.all(16.0), -// child: Column( -// //crossAxisAlignment: CrossAxisAlignment.start, -// children: [ -// Container( -// width: 350.0, -// child: Text( -// 'Convert blood sugar/glucose from mmol/l (UK standard) to mg/dlt (US standard) and vice versa.', -// //textAlign: TextAlign.center, -// style: TextStyle(fontSize: 20.0), -// ), -// ), -// SizedBox( -// height: 15.0, -// ), -// Container( -// color: Colors.white, -// height: 120.0, -// child: Padding( -// padding: const EdgeInsets.all(8.0), -// child: Column( -// //crossAxisAlignment: CrossAxisAlignment.end, -// children: [ -// Padding( -// padding: const EdgeInsets.symmetric(horizontal: 15.0), -// child: Row( -// children: [ -// Texts( -// 'Convert from', -// ) -// ], -// ), -// ), -// SizedBox( -// height: 9.0, -// ), -// Row( -// mainAxisAlignment: MainAxisAlignment.spaceEvenly, -// children: [ -// GestureDetector( -// onTap: () { -// setState(() { -// updateColor(1); -// finalValue = textController.text * 3; -// }); -// }, -// child: Container( -// height: 55.0, -// width: 150.0, -// decoration: BoxDecoration( -// color: cardMGColor, -// borderRadius: BorderRadius.circular(10.0), -// ), -// child: Padding( -// padding: const EdgeInsets.symmetric( -// vertical: 0.0, horizontal: 18.0), -// child: Texts('MG/DLt TO \nMMOL/L'), -// ), -// ), -// ), -// GestureDetector( -// onTap: () { -// setState(() { -// updateColor(2); -// finalValue = textController.text * 6; -// }); -// }, -// child: Container( -// height: 55.0, -// width: 150.0, -// decoration: BoxDecoration( -// color: cardMMOLColor, -// borderRadius: BorderRadius.circular(10.0), -// ), -// child: Padding( -// padding: -// const EdgeInsets.symmetric(horizontal: 16.0), -// child: Texts('MG/DLt TO\n MMOL/L'), -// ), -// ), -// ), -// ], -// ), -// ], -// ), -// ), -// ), -// SizedBox( -// height: 25.0, -// ), -// Container( -// height: 55.0, -// color: Colors.white, -// child: TextFormField( -// controller: textController, -// inputFormatters: [ -// FilteringTextInputFormatter.digitsOnly -// ], -// keyboardType: TextInputType.number, -// decoration: InputDecoration( -// labelText: " Enter the reading value", -// ), -// ), -// ), -// SizedBox( -// height: 5.0, -// ), -// Visibility( -// visible: _visible, -// child: Container( -// height: 95.0, -// width: 350.0, -// decoration: BoxDecoration( -// color: Colors.white, -// border: Border.all(color: Colors.black), -// borderRadius: BorderRadius.circular(15.0), -// ), -// child: Padding( -// padding: const EdgeInsets.all(8.0), -// child: Column( -// crossAxisAlignment: CrossAxisAlignment.start, -// mainAxisAlignment: MainAxisAlignment.center, -// children: [ -// Texts('Result:'), -// Text( -// finalValue.toString(), -// style: TextStyle(fontSize: 35.0), -// ), -// ], -// ), -// ), -// ), -// ), -// SizedBox( -// height: 15.0, -// ), -// Flexible( -// child: Container( -// height: 100.0, -// width: 150.0, -// child: Button( -// label: 'CALCULATE', -// onTap: () { -// setState(() { -// _visible = !_visible; -// }); -// }, -// ), -// ), -// ), -// ], -// ), -// ), -// ); -// } -// } +import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; +import 'package:diplomaticquarterapp/widgets/buttons/button.dart'; +import 'package:diplomaticquarterapp/widgets/buttons/secondary_button.dart'; +import 'package:diplomaticquarterapp/widgets/data_display/text.dart'; +import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; + +const activeCardColor = Color(0xff70777A); +const inactiveCardColor = Color(0xffFAFAFd); + +class BloodSugar extends StatefulWidget { + @override + _BloodSugarState createState() => _BloodSugarState(); +} + +Color color; + +class _BloodSugarState extends State { + Color cardMGColor = inactiveCardColor; + Color cardMMOLColor = inactiveCardColor; + + void updateColor(int type) { + //MG/DLT card + if (type == 1) { + if (cardMGColor == inactiveCardColor) { + cardMGColor = activeCardColor; + cardMMOLColor = inactiveCardColor; + } else { + cardMGColor = inactiveCardColor; + } + } + if (type == 2) { + if (cardMMOLColor == inactiveCardColor) { + cardMMOLColor = activeCardColor; + cardMGColor = inactiveCardColor; + } else { + cardMMOLColor = inactiveCardColor; + } + } + } + + void calculateBloodSugar() { + if (cardMGColor == activeCardColor) { + inputValue = double.parse(textController.text); + inputValue = inputValue / 15; + unit = 'mmol/l'; + } else if (cardMMOLColor == activeCardColor) { + inputValue = double.parse(textController.text); + inputValue = inputValue * 18; + unit = 'mg/dlt'; + } + } + + bool _visible = false; + TextEditingController textController = new TextEditingController(); + String finalValue; + + double inputValue = 0; + String unit; + + @override + Widget build(BuildContext context) { + return AppScaffold( + isShowAppBar: true, + appBarTitle: 'Blood Sugar Conversion', + body: Padding( + padding: const EdgeInsets.all(16.0), + child: SingleChildScrollView( + child: Container( + height: MediaQuery.of(context).size.height * 0.7, + child: Column( + //crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Container( + width: 350.0, + child: Text( + 'Convert blood sugar/glucose from mmol/l (UK standard) to mg/dlt (US standard) and vice versa.', + //textAlign: TextAlign.center, + style: TextStyle(fontSize: 20.0), + ), + ), + SizedBox( + height: 15.0, + ), + Container( + color: Colors.white, + height: 120.0, + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Column( + //crossAxisAlignment: CrossAxisAlignment.end, + children: [ + Padding( + padding: const EdgeInsets.symmetric(horizontal: 15.0), + child: Row( + children: [ + Texts( + 'Convert from', + ) + ], + ), + ), + SizedBox( + height: 9.0, + ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + GestureDetector( + onTap: () { + setState(() { + updateColor(1); + inputValue = + double.parse(textController.text); + inputValue = inputValue / 15; + unit = 'mmol/l'; + }); + }, + child: Container( + height: 55.0, + width: 150.0, + decoration: BoxDecoration( + boxShadow: [ + BoxShadow( + color: Colors.grey.withOpacity(0.5), + spreadRadius: 3, + blurRadius: 7, + offset: Offset( + 0, 3), // changes position of shadow + ), + ], + color: cardMGColor, + borderRadius: BorderRadius.circular(3.0), + ), + child: Padding( + padding: const EdgeInsets.symmetric( + vertical: 0.0, horizontal: 18.0), + child: Texts('MG/DLt TO \nMMOL/L'), + ), + ), + ), + GestureDetector( + onTap: () { + setState(() { + updateColor(2); + inputValue = + double.parse(textController.text); + inputValue = inputValue * 18; + unit = 'mg/dlt'; + }); + }, + child: Container( + height: 55.0, + width: 150.0, + decoration: BoxDecoration( + color: cardMMOLColor, + borderRadius: BorderRadius.circular(3.0), + boxShadow: [ + BoxShadow( + color: Colors.grey.withOpacity(0.5), + spreadRadius: 3, + blurRadius: 7, + offset: Offset( + 0, 3), // changes position of shadow + ), + ], + ), + child: Padding( + padding: const EdgeInsets.symmetric( + horizontal: 16.0), + child: Texts('MG/DLt TO\n MMOL/L'), + ), + ), + ), + ], + ), + ], + ), + ), + ), + SizedBox( + height: 25.0, + ), + Container( + height: 65.0, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(6.0), + color: Colors.white, + ), + child: TextFormField( + controller: textController, + inputFormatters: [ + FilteringTextInputFormatter.digitsOnly + ], + keyboardType: TextInputType.number, + decoration: InputDecoration( + labelText: " Enter the reading value", + border: OutlineInputBorder( + borderSide: BorderSide(color: Colors.black45)), + labelStyle: TextStyle( + color: Colors.black87, + ), + ), + ), + ), + SizedBox( + height: 25.0, + ), + Visibility( + visible: _visible, + child: Container( + height: 95.0, + width: 350.0, + decoration: BoxDecoration( + color: Colors.white, + border: Border.all(color: Colors.black), + borderRadius: BorderRadius.circular(15.0), + ), + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Texts('Result:'), + Row( + children: [ + Text( + inputValue.toStringAsFixed(3), + style: TextStyle(fontSize: 35.0), + ), + Padding( + padding: EdgeInsets.only(left: 4.0, top: 10.0), + child: Text( + unit.toString(), + style: TextStyle( + color: Color(0xffC5273A), + fontSize: 15.0, + fontWeight: FontWeight.w500, + ), + ), + ), + ], + ), + ], + ), + ), + ), + ), + SizedBox( + height: 30.0, + ), + Flexible( + child: Container( + height: 100.0, + width: 150.0, + child: Button( + label: 'CALCULATE', + onTap: () { + setState(() { + _visible == false + ? _visible = !_visible + : _visible = _visible; + calculateBloodSugar(); + }); + }, + ), + ), + ), + ], + ), + ), + ), + ), + ); + } +} diff --git a/lib/pages/AlHabibMedicalService/health_converter/triglycerides.dart b/lib/pages/AlHabibMedicalService/health_converter/triglycerides.dart new file mode 100644 index 00000000..fdf8d191 --- /dev/null +++ b/lib/pages/AlHabibMedicalService/health_converter/triglycerides.dart @@ -0,0 +1,275 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; + +import 'package:diplomaticquarterapp/widgets/buttons/button.dart'; +import 'package:diplomaticquarterapp/widgets/buttons/secondary_button.dart'; +import 'package:diplomaticquarterapp/widgets/data_display/text.dart'; +import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; + +import 'package:flutter/services.dart'; + +const activeCardColor = Color(0xff70777A); +const inactiveCardColor = Color(0xffFAFAFd); + +class Triglycerides extends StatefulWidget { + @override + _TriglyceridesState createState() => _TriglyceridesState(); +} + +class _TriglyceridesState extends State { + Color cardMGColor = inactiveCardColor; + Color cardMMOLColor = inactiveCardColor; + int type; + void updateColor(type) { + //MG/DLT card + if (type == 1) { + if (cardMGColor == inactiveCardColor) { + cardMGColor = activeCardColor; + cardMMOLColor = inactiveCardColor; + } else { + cardMGColor = inactiveCardColor; + } + } + if (type == 2) { + if (cardMMOLColor == inactiveCardColor) { + cardMMOLColor = activeCardColor; + cardMGColor = inactiveCardColor; + } else { + cardMMOLColor = inactiveCardColor; + } + } + } + + void calculateTriglycerides() { + if (cardMGColor == activeCardColor) { + inputValue = double.parse(textController.text); + inputValue = inputValue / conversionConst; + unit = 'mmol/l'; + } else if (cardMMOLColor == activeCardColor) { + inputValue = double.parse(textController.text); + inputValue = inputValue * conversionConst; + unit = 'mg/dlt'; + } + } + + bool _visible = false; + TextEditingController textController = new TextEditingController(); + String finalValue; + + double inputValue = 0.0; + String unit; + double conversionConst = 88.57; + + @override + Widget build(BuildContext context) { + return AppScaffold( + isShowAppBar: true, + appBarTitle: 'Triglycerides', + body: Padding( + padding: const EdgeInsets.all(16.0), + child: SingleChildScrollView( + child: Container( + height: MediaQuery.of(context).size.height * 0.7, + child: Column( + //crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Container( + width: 350.0, + child: Text( + 'Convert Triglycerides from mmol/l to\n mg/dlt and vice versa.', + //textAlign: TextAlign.center, + style: TextStyle(fontSize: 20.0), + ), + ), + SizedBox( + height: 15.0, + ), + Container( + color: Colors.white, + height: 120.0, + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Column( + //crossAxisAlignment: CrossAxisAlignment.end, + children: [ + Padding( + padding: const EdgeInsets.symmetric(horizontal: 15.0), + child: Row( + children: [Texts('Convert from')], + ), + ), + SizedBox( + height: 9.0, + ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + children: [ + GestureDetector( + onTap: () { + setState(() { + updateColor(1); + inputValue = + double.parse(textController.text); + inputValue = inputValue / conversionConst; + unit = 'mmol/l'; + }); + }, + child: Container( + height: 55.0, + width: 150.0, + decoration: BoxDecoration( + boxShadow: [ + BoxShadow( + color: Colors.grey.withOpacity(0.5), + spreadRadius: 3, + blurRadius: 7, + offset: Offset( + 0, 3), // changes position of shadow + ), + ], + color: cardMGColor, + borderRadius: BorderRadius.circular(3.0), + ), + child: Padding( + padding: const EdgeInsets.symmetric( + vertical: 0.0, horizontal: 18.0), + child: Texts('MG/DLt TO \nMMOL/L'), + ), + ), + ), + GestureDetector( + onTap: () { + setState(() { + updateColor(2); + inputValue = + double.parse(textController.text); + inputValue = inputValue * conversionConst; + unit = 'mg/dlt'; + }); + }, + child: Container( + height: 55.0, + width: 150.0, + decoration: BoxDecoration( + color: cardMMOLColor, + borderRadius: BorderRadius.circular(3.0), + boxShadow: [ + BoxShadow( + color: Colors.grey.withOpacity(0.5), + spreadRadius: 3, + blurRadius: 7, + offset: Offset( + 0, 3), // changes position of shadow + ), + ], + ), + child: Padding( + padding: const EdgeInsets.symmetric( + horizontal: 16.0), + child: Texts('MG/DLt TO\n MMOL/L'), + ), + ), + ), + ], + ), + ], + ), + ), + ), + SizedBox( + height: 25.0, + ), + Container( + height: 65.0, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(6.0), + color: Colors.white, + ), + child: TextFormField( + controller: textController, + inputFormatters: [ + FilteringTextInputFormatter.digitsOnly + ], + keyboardType: TextInputType.number, + decoration: InputDecoration( + border: OutlineInputBorder( + borderSide: BorderSide(color: Colors.black45)), + labelText: " Enter the reading value", + labelStyle: TextStyle( + color: Colors.black87, + ), + ), + ), + ), + SizedBox( + height: 25.0, + ), + Visibility( + visible: _visible, + child: Container( + height: 95.0, + width: 350.0, + decoration: BoxDecoration( + color: Colors.white, + border: Border.all(color: Colors.black), + borderRadius: BorderRadius.circular(15.0), + ), + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Texts('Result:'), + Row( + children: [ + Text( + inputValue.toStringAsFixed(2), + style: TextStyle(fontSize: 35.0), + ), + Padding( + padding: EdgeInsets.only(left: 4.0, top: 10.0), + child: Text( + unit.toString(), + style: TextStyle( + color: Color(0xffC5273A), + fontSize: 15.0, + fontWeight: FontWeight.w500, + ), + ), + ), + ], + ), + ], + ), + ), + ), + ), + SizedBox( + height: 10.0, + ), + Flexible( + child: Container( + height: 100.0, + width: 250.0, + child: Button( + label: 'CALCULATE', + onTap: () { + setState(() { + _visible == false + ? _visible = !_visible + : _visible = _visible; + calculateTriglycerides(); + }); + }, + ), + ), + ), + ], + ), + ), + ), + ), + ); + } +}