Last active
September 4, 2018 04:14
-
-
Save liemvo/2aaedb43946dc006315b87a137c12bcc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RaisedButton calculateButton() { | |
return RaisedButton( | |
onPressed: _calculator, | |
color: Colors.pinkAccent, | |
child: Text( | |
'Calculate', | |
style: TextStyle(fontSize: 16.9), | |
), | |
textColor: Colors.white70, | |
); | |
} | |
TextFormField weightFormField() { | |
return TextFormField( | |
controller: _weightController, | |
keyboardType: TextInputType.number, | |
textInputAction: TextInputAction.done, | |
focusNode: _weightFocus, | |
onFieldSubmitted: (value){ | |
_weightFocus.unfocus(); | |
_calculator(); | |
}, | |
validator: (value) { | |
if (value.length == 0 || double.parse(value) == 0.0) { | |
return ('Weight is not valid. Weight > 0.0'); | |
} | |
}, | |
onSaved: (value) { | |
_weight = value; | |
}, | |
decoration: InputDecoration( | |
hintText: _weightMessage, | |
labelText: _weightMessage, | |
icon: Icon(Icons.menu), | |
fillColor: Colors.white | |
), | |
); | |
} | |
TextFormField heightFormField(BuildContext context) { | |
return TextFormField( | |
controller: _heightController, | |
keyboardType: TextInputType.number, | |
textInputAction: TextInputAction.next, | |
focusNode: _heightFocus, | |
onFieldSubmitted: (term) { | |
_fieldFocusChange(context, _heightFocus, _weightFocus); | |
}, | |
validator: (value) { | |
if (value.length == 0 || double.parse(value) == 0.0) { | |
return ('Height is not valid. Height > 0.0'); | |
} | |
}, | |
onSaved: (value) { | |
_height = value; | |
}, | |
decoration: InputDecoration( | |
hintText: _heightMessage, | |
icon: Icon(Icons.assessment), | |
fillColor: Colors.white, | |
), | |
); | |
} | |
TextFormField ageFormField(BuildContext context) { | |
return TextFormField( | |
keyboardType: TextInputType.number, | |
textInputAction: TextInputAction.next, | |
focusNode: _ageFocus, | |
onFieldSubmitted: (term){ | |
_fieldFocusChange(context, _ageFocus, _heightFocus); | |
}, | |
validator: (value) { | |
if (value.length == 0 || double.parse(value) <= 15) { | |
return ('Age should be over 15 years old'); | |
} | |
}, | |
onSaved: (value) { | |
_age = value; | |
}, | |
decoration: InputDecoration( | |
hintText: 'Age', | |
icon: Icon(Icons.person_outline), | |
fillColor: Colors.white, | |
), | |
); | |
} | |
void _calculator() { | |
if (_formKey.currentState.validate()) { | |
_formKey.currentState.save(); | |
this.widget.presenter.onCalculateClicked(_weight, _height); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment