@ -1,10 +1,11 @@
import ' package:diplomaticquarterapp/theme/colors.dart ' ;
import ' package:diplomaticquarterapp/uitl/translations_delegate_base.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:diplomaticquarterapp/widgets/transitions/fade_page.dart ' ;
import ' package:flutter/material.dart ' ;
import ' package:flutter/services.dart ' ;
import ' ideal_body_result_page.dart ' ;
@ -24,8 +25,9 @@ class _IdealBodyState extends State<IdealBody> {
Color lbCard = inactiveCardColor ;
Color cmCard = activeCardColor ;
Color ftCard = inactiveCardColor ;
int age = 0 ;
int height = 0 ;
/ / int age = 0 ;
/ / int height = 0 ;
double heightInches ;
double minRange ;
double maxRange ;
@ -38,48 +40,22 @@ class _IdealBodyState extends State<IdealBody> {
double maxIdealWeight ;
double heightFeet ;
void updateColorHeight ( int type ) {
/ / MG / DLT card
if ( type = = 1 ) {
if ( cmCard = = inactiveCardColor ) {
cmCard = activeCardColor ;
ftCard = inactiveCardColor ;
} else {
cmCard = inactiveCardColor ;
}
}
if ( type = = 2 ) {
if ( ftCard = = inactiveCardColor ) {
ftCard = activeCardColor ;
cmCard = inactiveCardColor ;
} else {
ftCard = inactiveCardColor ;
}
}
}
final GlobalKey clinicDropdownKey = GlobalKey ( ) ;
bool _isHeightCM = true ;
bool _isWeightKG = true ;
double _heightValue = 0 ;
double _weightValue = 0 ;
TextEditingController _heightController = new TextEditingController ( ) ;
TextEditingController _weightController = TextEditingController ( ) ;
List < PopupMenuItem > _heightPopupList = List ( ) ;
List < PopupMenuItem > _weightPopupList = List ( ) ;
void updateColorWeight ( int type ) {
/ / MG / DLT card
if ( type = = 1 ) {
if ( kgCard = = inactiveCardColor ) {
kgCard = activeCardColor ;
lbCard = inactiveCardColor ;
} else {
kgCard = inactiveCardColor ;
}
}
if ( type = = 2 ) {
if ( lbCard = = inactiveCardColor ) {
lbCard = activeCardColor ;
kgCard = inactiveCardColor ;
} else {
lbCard = inactiveCardColor ;
}
}
}
void calculateIdealWeight ( ) {
heightInches = height * . 39370078740157477 ;
heightInches = int . parse ( _heightController . text ) * . 39370078740157477 ;
heightFeet = heightInches / 12 ;
idealWeight = ( 50 + 2.3 * ( heightInches - 60 ) ) ;
if ( dropdownValue = = ' Small(fingers overlap) ' ) {
@ -99,6 +75,9 @@ class _IdealBodyState extends State<IdealBody> {
@ override
Widget build ( BuildContext context ) {
_weightPopupList = < PopupMenuItem > [ PopupMenuItem ( child: Text ( TranslationBase . of ( context ) . kg ) , value: true ) , PopupMenuItem ( child: Text ( TranslationBase . of ( context ) . lb ) , value: false ) ] ;
_heightPopupList = < PopupMenuItem > [ PopupMenuItem ( child: Text ( TranslationBase . of ( context ) . cm ) , value: true ) , PopupMenuItem ( child: Text ( TranslationBase . of ( context ) . ft ) , value: false ) ] ;
return AppScaffold (
isShowAppBar: true ,
isShowDecPage: false ,
@ -115,458 +94,418 @@ class _IdealBodyState extends State<IdealBody> {
) ,
)
] ,
body: Padding (
padding: EdgeInsets . symmetric ( vertical: 15.0 , horizontal: 25.0 ) ,
child: SingleChildScrollView (
child: Container (
height: 800.0 ,
child: Column (
children: [
Padding (
padding: EdgeInsets . all ( 10.0 ) ,
child: Texts (
' Calculates the ideal body weight based on height, Weight, and Body Size ' ,
) ,
) ,
Divider (
thickness: 2.0 ,
) ,
SizedBox (
height: 5.0 ,
) ,
Column (
crossAxisAlignment: CrossAxisAlignment . start ,
body: Column (
children: [
Expanded (
child: SingleChildScrollView (
child: Container (
padding: EdgeInsets . all ( 21 ) ,
child: Column (
children: [
Texts (
' Height ' ,
) ,
Row (
children: [
Expanded (
child: Container (
width: 340.0 ,
height: 60.0 ,
decoration: BoxDecoration (
color: Colors . white ,
) ,
child: Row (
children: [
Padding (
padding: EdgeInsets . symmetric (
vertical: 10.0 , horizontal: 8.0 ) ,
child: Center (
child: Container (
width: 60.0 ,
foregroundDecoration: BoxDecoration (
borderRadius:
BorderRadius . circular ( 5.0 ) ,
border: Border . all (
color: Colors . blueGrey ,
width: 2.0 ,
) ,
) ,
child: Row (
children: < Widget > [
Expanded (
child: Center (
child: Text ( height . toString ( ) ) ,
) ,
) ,
Container (
height: 38.0 ,
child: Column (
crossAxisAlignment:
CrossAxisAlignment . center ,
mainAxisAlignment:
MainAxisAlignment . center ,
children: < Widget > [
Container (
decoration: BoxDecoration (
border: Border (
bottom: BorderSide (
width: 0.5 ,
) ,
) ,
) ,
child: InkWell (
child: Icon (
Icons . arrow_drop_up ,
size: 18.0 ,
) ,
onTap: ( ) {
setState ( ( ) {
if ( height < 250 )
height + + ;
} ) ;
} ,
) ,
) ,
InkWell (
child: Icon (
Icons . arrow_drop_down ,
size: 18.0 ,
) ,
onTap: ( ) {
setState ( ( ) {
if ( height > 0 ) height - - ;
} ) ;
} ,
) ,
] ,
) ,
) ,
] ,
) ,
) ,
) ,
) ,
Expanded (
child: Slider (
value: height . toDouble ( ) ,
min: 0 ,
max: 250 ,
onChanged: ( double newValue ) {
setState ( ( ) {
height = newValue . round ( ) ;
} ) ;
} ,
activeColor: Color ( 0xffC5272D ) ,
inactiveColor: Color ( 0xffF3C5C6 ) ,
) ,
) ,
] ,
) ,
) ,
) ,
] ,
Text (
' Calculates the ideal body weight based on height, Weight, and Body Size ' ,
style: TextStyle (
fontSize: 14 ,
fontWeight: FontWeight . w600 ,
letterSpacing: - 0.56 ,
color: CustomColors . textColor ,
) ,
) ,
Texts ( ' Select Unit ' ) ,
SizedBox (
height: 5.0 ,
) ,
Row (
mainAxisAlignment: MainAxisAlignment . spaceEvenly ,
Column (
crossAxisAlignment: CrossAxisAlignment . start ,
children: [
GestureDetector (
onTap: ( ) {
setState ( ( ) {
updateColorHeight ( 1 ) ;
isHeightCm = true ;
} ) ;
SizedBox (
height: 12.0 ,
) ,
_commonInputAndUnitRow (
TranslationBase . of ( context ) . height ,
_heightController ,
1 ,
270 ,
_heightValue ,
( text ) {
_heightController . text = text ;
} ,
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: cmCard ,
borderRadius: BorderRadius . circular ( 3.0 ) ,
) ,
child: Padding (
padding: const EdgeInsets . symmetric (
vertical: 0.0 , horizontal: 18.0 ) ,
child: Center ( child: Texts ( ' CM ' ) ) ,
) ,
) ,
( value ) {
_heightValue = value ;
} ,
_isHeightCM ? TranslationBase . of ( context ) . cm : TranslationBase . of ( context ) . ft ,
( value ) {
if ( _isHeightCM ! = value ) {
setState ( ( ) {
_isHeightCM = value ;
} ) ;
}
} ,
_heightPopupList ,
) ,
GestureDetector (
onTap: ( ) {
setState ( ( ) {
updateColorHeight ( 2 ) ;
isHeightCm = false ;
} ) ;
SizedBox (
height: 12.0 ,
) ,
_commonInputAndUnitRow (
TranslationBase . of ( context ) . weight ,
_weightController ,
1 ,
270 ,
_weightValue ,
( text ) {
_weightController . text = text ;
} ,
child: Container (
height: 55.0 ,
width: 150.0 ,
decoration: BoxDecoration (
color: ftCard ,
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: Center ( child: Texts ( ' Ft ' ) ) ,
) ,
) ,
( value ) {
_weightValue = value ;
} ,
_isWeightKG ? TranslationBase . of ( context ) . kg : TranslationBase . of ( context ) . pound ,
( value ) {
if ( _isWeightKG ! = value ) {
setState ( ( ) {
_isWeightKG = value ;
} ) ;
}
} ,
_weightPopupList ,
) ,
] ,
) ,
SizedBox (
height: 45.0 ,
) ,
Divider (
thickness: 2.0 ,
) ,
Texts (
' Weight ' ,
) ,
SizedBox (
height: 5.0 ,
) ,
Row (
children: [
Expanded (
SizedBox (
height: 12.0 ,
) ,
InkWell (
onTap: ( ) {
/ / dropdownKey . currentState ;
openDropdown ( clinicDropdownKey ) ;
} ,
child: Container (
width: 340.0 ,
height: 60.0 ,
decoration: BoxDecoration (
color: Colors . white ,
) ,
/ / width: double . infinity ,
/ / decoration: containerRadius ( Colors . white , 12 ) ,
/ / padding: EdgeInsets . only ( left: 10 , right: 10 , top: 12 , bottom: 12 ) ,
child: Row (
children: [
Padding (
padding: EdgeInsets . symmetric (
vertical: 10.0 , horizontal: 8.0 ) ,
child: Center (
child: Container (
width: 60.0 ,
foregroundDecoration: BoxDecoration (
borderRadius:
BorderRadius . circular ( 5.0 ) ,
border: Border . all (
color: Colors . blueGrey ,
width: 2.0 ,
Flexible (
child: Column (
crossAxisAlignment: CrossAxisAlignment . start ,
children: [
Text (
" Body Frame Size " ,
style: TextStyle (
fontSize: 11 ,
letterSpacing: - 0.44 ,
fontWeight: FontWeight . w600 ,
) ,
) ,
child: Row (
children: < Widget > [
Expanded (
child: Center (
child: Text ( weight . toString ( ) ) ,
) ,
) ,
Container (
height: 38.0 ,
child: Column (
crossAxisAlignment:
CrossAxisAlignment . center ,
mainAxisAlignment:
MainAxisAlignment . center ,
children: < Widget > [
Container (
decoration: BoxDecoration (
border: Border (
bottom: BorderSide (
width: 0.5 ,
) ,
) ,
) ,
child: InkWell (
child: Icon (
Icons . arrow_drop_up ,
size: 18.0 ,
) ,
onTap: ( ) {
setState ( ( ) {
if ( weight < 250 )
weight + + ;
} ) ;
} ,
) ,
) ,
InkWell (
child: Icon (
Icons . arrow_drop_down ,
size: 18.0 ,
) ,
onTap: ( ) {
setState ( ( ) {
if ( weight > 0 ) weight - - ;
} ) ;
} ,
) ,
] ,
Container (
height: 18 ,
child: DropdownButtonHideUnderline (
child: DropdownButton < String > (
value: dropdownValue ,
icon: Icon ( Icons . arrow_downward ) ,
iconSize: 0 ,
elevation: 16 ,
isExpanded: true ,
style: TextStyle ( color: Colors . black87 ) ,
underline: Container (
height: 2 ,
color: Colors . black54 ,
) ,
onChanged: ( String newValue ) {
setState ( ( ) {
dropdownValue = newValue ;
} ) ;
} ,
items: < String > [
' Small(fingers overlap) ' ,
' Medium(fingers touch) ' ,
' Large(fingers don \' n touch) ' ,
] . map < DropdownMenuItem < String > > ( ( String value ) {
return DropdownMenuItem < String > (
value: value ,
child: Text ( value ) ,
) ;
} ) . toList ( ) ,
) ,
] ,
) ,
) ,
) ,
) ,
) ,
Expanded (
child: Slider (
value: weight . toDouble ( ) ,
min: 0 ,
max: 250 ,
onChanged: ( double newValue ) {
setState ( ( ) {
weight = newValue . round ( ) ;
} ) ;
} ,
activeColor: Color ( 0xffC5272D ) ,
inactiveColor: Color ( 0xffF3C5C6 ) ,
] ,
) ,
) ,
Icon ( Icons . keyboard_arrow_down ) ,
] ,
) ,
) ,
) ,
] ,
) ,
Texts ( ' Select Unit ' ) ,
SizedBox (
height: 5.0 ,
) ,
Row (
mainAxisAlignment: MainAxisAlignment . spaceEvenly ,
children: [
GestureDetector (
onTap: ( ) {
setState ( ( ) {
updateColorWeight ( 1 ) ;
} ) ;
} ,
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: kgCard ,
borderRadius: BorderRadius . circular ( 3.0 ) ,
) ,
child: Padding (
padding: const EdgeInsets . symmetric (
vertical: 0.0 , horizontal: 18.0 ) ,
child: Center ( child: Texts ( ' KG ' ) ) ,
) ,
) ,
) ,
GestureDetector (
onTap: ( ) {
setState ( ( ) {
updateColorWeight ( 2 ) ;
} ) ;
} ,
child: Container (
height: 55.0 ,
width: 150.0 ,
decoration: BoxDecoration (
color: lbCard ,
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: Center ( child: Texts ( ' LB ' ) ) ,
) ,
) ,
) . withBorderedContainer ,
) ,
] ,
) ,
SizedBox (
height: 45.0 ,
) ,
Divider (
thickness: 2.0 ,
] ,
) ,
) ,
) ,
) ,
Container (
margin: EdgeInsets . symmetric ( horizontal: 16.0 , vertical: 16.0 ) ,
color: Colors . white ,
child: SecondaryButton (
label: TranslationBase . of ( context ) . calculate ,
color: CustomColors . accentColor ,
onTap: ( ) {
setState ( ( ) {
/ / calculateBmr ( ) ;
/ / calculateCalories ( ) ;
calculateIdealWeight ( ) ;
print ( idealWeight ) ;
print ( minRange ) ;
print ( maxRange ) ;
print ( overWeightBy ) ;
print ( textResult ) ;
/ / print ( overWeightBy ) ;
{
Navigator . push (
context ,
FadePage (
page: IdealBodyResult (
idealBodyWeight: idealWeight ,
minRange: minRange ,
mixRange: maxRange ,
overWeightBy: overWeightBy ,
textResult: textResult ,
) ) ,
) ;
}
} ) ;
} ,
) ,
) ,
] ,
) ,
) ;
}
void openDropdown ( GlobalKey key ) {
GestureDetector detector ;
void searchForGestureDetector ( BuildContext element ) {
element . visitChildElements ( ( element ) {
if ( element . widget ! = null & & element . widget is GestureDetector ) {
detector = element . widget ;
return false ;
} else {
searchForGestureDetector ( element ) ;
}
return true ;
} ) ;
}
searchForGestureDetector ( key . currentContext ) ;
assert ( detector ! = null ) ;
detector . onTap ( ) ;
}
Widget inputWidget ( String _labelText , String _hintText , TextEditingController _controller , { String prefix , bool isEnable = true , bool hasSelection = false } ) {
return Container (
padding: EdgeInsets . only ( left: 16 , right: 16 , bottom: 15 , top: 15 ) ,
alignment: Alignment . center ,
decoration: BoxDecoration (
borderRadius: BorderRadius . circular ( 15 ) ,
color: Colors . white ,
border: Border . all (
color: Color ( 0xffefefef ) ,
width: 1 ,
) ,
) ,
child: InkWell (
onTap: hasSelection ? ( ) { } : null ,
child: Row (
children: [
Expanded (
child: Column (
mainAxisSize: MainAxisSize . min ,
crossAxisAlignment: CrossAxisAlignment . start ,
children: [
Text (
_labelText ,
style: TextStyle (
fontSize: 11 ,
fontWeight: FontWeight . w600 ,
color: Color ( 0xff2B353E ) ,
letterSpacing: - 0.44 ,
) ,
SizedBox (
height: 5.0 ,
) ,
TextField (
enabled: isEnable ,
scrollPadding: EdgeInsets . zero ,
keyboardType: TextInputType . number ,
controller: _controller ,
onChanged: ( value ) = > { } ,
style: TextStyle (
fontSize: 14 ,
height: 21 / 14 ,
fontWeight: FontWeight . w400 ,
color: Color ( 0xff2B353E ) ,
letterSpacing: - 0.44 ,
) ,
Texts ( ' Body Frame Size ' ) ,
Container (
width: 300 ,
child: DropdownButton < String > (
value: dropdownValue ,
icon: Icon ( Icons . arrow_downward ) ,
iconSize: 24 ,
elevation: 16 ,
style: TextStyle ( color: Colors . black87 ) ,
underline: Container (
height: 2 ,
color: Colors . black54 ,
) ,
onChanged: ( String newValue ) {
setState ( ( ) {
dropdownValue = newValue ;
} ) ;
} ,
items: < String > [
' Small(fingers overlap) ' ,
' Medium(fingers touch) ' ,
' Large(fingers don \' n touch) ' ,
] . map < DropdownMenuItem < String > > ( ( String value ) {
return DropdownMenuItem < String > (
value: value ,
child: Text ( value ) ,
) ;
} ) . toList ( ) ,
decoration: InputDecoration (
isDense: true ,
hintText: _hintText ,
hintStyle: TextStyle (
fontSize: 14 ,
height: 21 / 14 ,
fontWeight: FontWeight . w400 ,
color: Color ( 0xff575757 ) ,
letterSpacing: - 0.56 ,
) ,
prefixIconConstraints: BoxConstraints ( minWidth: 50 ) ,
prefixIcon: prefix = = null
? null
: Text (
" + " + prefix ,
style: TextStyle (
fontSize: 14 ,
height: 21 / 14 ,
fontWeight: FontWeight . w500 ,
color: Color ( 0xff2E303A ) ,
letterSpacing: - 0.56 ,
) ,
) ,
contentPadding: EdgeInsets . zero ,
border: InputBorder . none ,
focusedBorder: InputBorder . none ,
enabledBorder: InputBorder . none ,
) ,
SizedBox (
height: 30.0 ,
) ,
Container (
height: 50.0 ,
width: 350.0 ,
child: SecondaryButton (
label: ' CALCULATE ' ,
onTap: ( ) {
setState ( ( ) {
/ / calculateBmr ( ) ;
/ / calculateCalories ( ) ;
calculateIdealWeight ( ) ;
) ,
] ,
) ,
) ,
if ( hasSelection ) Icon ( Icons . keyboard_arrow_down_outlined ) ,
] ,
) ,
) ,
) ;
}
print ( idealWeight ) ;
/ / print ( overWeightBy ) ;
{
Navigator . push (
context ,
FadePage (
page: IdealBodyResult (
idealBodyWeight: idealWeight ,
minRange: minRange ,
mixRange: maxRange ,
overWeightBy: overWeightBy ,
textResult: textResult ,
) ) ,
) ;
}
} ) ;
} ,
) ,
) ,
] ,
Widget _commonInputAndUnitRow ( _title , _controller , double _minValue , double _maxValue , double _valueOrg , Function ( String ) onTextValueChange , Function ( double ) onValueChange , String unitTitle ,
Function ( bool ) onUnitTap , _list ) {
return Row (
children: [
Expanded (
flex: 3 ,
child: Column (
mainAxisSize: MainAxisSize . min ,
crossAxisAlignment: CrossAxisAlignment . start ,
children: [
Text (
_title ,
style: TextStyle (
fontSize: 12 ,
fontWeight: FontWeight . w600 ,
color: Color ( 0xff2E303A ) ,
letterSpacing: - 0.44 ,
) ,
] ,
) ,
) ,
TextField (
controller: _controller ,
keyboardType: TextInputType . number ,
onChanged: ( value ) {
double _value = double . parse ( value ) ;
if ( _value > _maxValue ) {
onTextValueChange ( _maxValue . toStringAsFixed ( 0 ) ) ;
onValueChange ( _maxValue ) ;
return ;
} else if ( _value < _minValue ) {
onTextValueChange ( _minValue . toStringAsFixed ( 0 ) ) ;
onValueChange ( _minValue ) ;
return ;
} else if ( _value > = _minValue & & _value < = _maxValue ) {
onValueChange ( _value ) ;
return ;
}
} ,
inputFormatters: [
FilteringTextInputFormatter . allow ( RegExp ( r'[0-9]' ) ) ,
] ,
style: TextStyle (
color: Color ( 0xff575757 ) ,
letterSpacing: - 0.56 ,
) ,
decoration: InputDecoration (
isDense: true ,
hintText: " 0 " ,
hintStyle: TextStyle (
fontSize: 14 ,
height: 21 / 14 ,
fontWeight: FontWeight . w400 ,
color: Color ( 0xff575757 ) ,
letterSpacing: - 0.56 ,
) ,
contentPadding: EdgeInsets . zero ,
border: InputBorder . none ,
focusedBorder: InputBorder . none ,
enabledBorder: InputBorder . none ,
) ,
) ,
] ,
) ,
) ,
Container ( height: 34 , width: 1 , color: Color ( 0xffE0E0E0 ) , margin: EdgeInsets . only ( left: 12 , right: 12 ) ) ,
Expanded (
flex: 1 ,
child: PopupMenuButton (
child: CommonDropDownView ( TranslationBase . of ( context ) . unit , unitTitle , null ) ,
onSelected: ( value ) {
onUnitTap ( value ) ;
} ,
itemBuilder: ( context ) = > _list ) ,
)
] ,
) . withBorderedContainer ;
}
}
/ / todo ' sikander ' move these to separate file once usability known
class CommonDropDownView extends StatelessWidget {
final String title ;
final String value ;
final VoidCallback callback ;
final IconData iconData ;
CommonDropDownView ( this . title , this . value , this . callback , { Key key , this . iconData } ) : super ( key: key ) ;
@ override
Widget build ( BuildContext context ) {
return InkWell (
onTap: callback ,
child: Row (
children: [
Expanded (
child: Column ( crossAxisAlignment: CrossAxisAlignment . start , children: [
Text (
title ,
style: TextStyle (
fontSize: 12 ,
fontWeight: FontWeight . w600 ,
color: Color ( 0xff2E303A ) ,
letterSpacing: - 0.44 ,
) ,
) ,
Text (
value ,
style: TextStyle (
fontSize: 14 ,
fontWeight: FontWeight . w400 ,
color: Color ( 0xff575757 ) ,
letterSpacing: - 0.56 ,
) ,
) ,
] ) ,
) ,
Icon (
iconData ? ? Icons . keyboard_arrow_down_sharp ,
color: Color ( 0xff2E303A ) ,
)
] ,
) ,
) ;
}
}