Add new mih text form field to Calc: Tip
This commit is contained in:
@@ -1,11 +1,13 @@
|
|||||||
import 'package:mzansi_innovation_hub/main.dart';
|
import 'package:mzansi_innovation_hub/main.dart';
|
||||||
|
import 'package:mzansi_innovation_hub/mih_apis/mih_alert_services.dart';
|
||||||
|
import 'package:mzansi_innovation_hub/mih_apis/mih_validation_services.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_components/mih_inputs_and_buttons/mih_dropdown_input.dart';
|
import 'package:mzansi_innovation_hub/mih_components/mih_inputs_and_buttons/mih_dropdown_input.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_components/mih_inputs_and_buttons/mih_number_input.dart';
|
|
||||||
import 'package:mzansi_innovation_hub/mih_components/mih_layout/mih_single_child_scroll.dart';
|
import 'package:mzansi_innovation_hub/mih_components/mih_layout/mih_single_child_scroll.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_button.dart';
|
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_button.dart';
|
||||||
|
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_form.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_tool_body.dart';
|
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_tool_body.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_window.dart';
|
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_package_window.dart';
|
||||||
import 'package:mzansi_innovation_hub/mih_components/mih_pop_up_messages/mih_error_message.dart';
|
import 'package:mzansi_innovation_hub/mih_components/mih_package_components/mih_text_form_field.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||||
import 'package:math_expressions/math_expressions.dart';
|
import 'package:math_expressions/math_expressions.dart';
|
||||||
@@ -23,9 +25,11 @@ class _TipCalcState extends State<TipCalc> {
|
|||||||
TextEditingController splitBillController = TextEditingController();
|
TextEditingController splitBillController = TextEditingController();
|
||||||
TextEditingController noPeopleController = TextEditingController();
|
TextEditingController noPeopleController = TextEditingController();
|
||||||
final ValueNotifier<String> splitValue = ValueNotifier("");
|
final ValueNotifier<String> splitValue = ValueNotifier("");
|
||||||
|
final _formKey = GlobalKey<FormState>();
|
||||||
String tip = "";
|
String tip = "";
|
||||||
String total = "";
|
String total = "";
|
||||||
String amountPerPerson = "";
|
String amountPerPerson = "";
|
||||||
|
String temp = "";
|
||||||
void splitSelected() {
|
void splitSelected() {
|
||||||
if (splitBillController.text.isNotEmpty) {
|
if (splitBillController.text.isNotEmpty) {
|
||||||
splitValue.value = splitBillController.text;
|
splitValue.value = splitBillController.text;
|
||||||
@@ -35,38 +39,7 @@ class _TipCalcState extends State<TipCalc> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void validateInput() async {
|
void validateInput() async {
|
||||||
bool valid = false;
|
|
||||||
if (splitBillController.text.isNotEmpty &&
|
|
||||||
splitBillController.text == "Yes") {
|
|
||||||
if (billAmountController.text.isEmpty ||
|
|
||||||
tipPercentageController.text.isEmpty ||
|
|
||||||
noPeopleController.text.isEmpty) {
|
|
||||||
valid = false;
|
|
||||||
} else {
|
|
||||||
valid = true;
|
|
||||||
}
|
|
||||||
} else if (splitBillController.text.isNotEmpty &&
|
|
||||||
splitBillController.text == "No") {
|
|
||||||
if (billAmountController.text.isEmpty ||
|
|
||||||
tipPercentageController.text.isEmpty) {
|
|
||||||
valid = false;
|
|
||||||
} else {
|
|
||||||
valid = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
valid = false;
|
|
||||||
}
|
|
||||||
print("Is input valid: $valid");
|
|
||||||
if (valid) {
|
|
||||||
calculatePressed();
|
calculatePressed();
|
||||||
} else {
|
|
||||||
showDialog(
|
|
||||||
context: context,
|
|
||||||
builder: (context) {
|
|
||||||
return const MIHErrorMessage(errorType: "Input Error");
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void calculatePressed() {
|
void calculatePressed() {
|
||||||
@@ -262,34 +235,70 @@ class _TipCalcState extends State<TipCalc> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
double screenWidth = MediaQuery.of(context).size.width;
|
||||||
return MihPackageToolBody(
|
return MihPackageToolBody(
|
||||||
borderOn: false,
|
borderOn: false,
|
||||||
innerHorizontalPadding: 10,
|
innerHorizontalPadding: 10,
|
||||||
bodyItem: getBody(),
|
bodyItem: getBody(screenWidth),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget getBody() {
|
Widget getBody(double width) {
|
||||||
return MihSingleChildScroll(
|
return MihSingleChildScroll(
|
||||||
|
child: Padding(
|
||||||
|
padding: MzanziInnovationHub.of(context)!.theme.screenType == "desktop"
|
||||||
|
? EdgeInsets.symmetric(horizontal: width * 0.2)
|
||||||
|
: EdgeInsets.symmetric(horizontal: width * 0.075),
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.max,
|
mainAxisSize: MainAxisSize.max,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
MIHNumberField(
|
MihForm(
|
||||||
|
formKey: _formKey,
|
||||||
|
formFields: [
|
||||||
|
MihTextFormField(
|
||||||
|
fillColor:
|
||||||
|
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||||
|
inputColor:
|
||||||
|
MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
||||||
controller: billAmountController,
|
controller: billAmountController,
|
||||||
|
multiLineInput: false,
|
||||||
|
requiredText: true,
|
||||||
hintText: "Bill Amount",
|
hintText: "Bill Amount",
|
||||||
editable: true,
|
numberMode: true,
|
||||||
required: true,
|
validator: (value) {
|
||||||
enableDecimal: true,
|
return MihValidationServices().isEmpty(value);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
|
// MIHNumberField(
|
||||||
|
// controller: billAmountController,
|
||||||
|
// hintText: "Bill Amount",
|
||||||
|
// editable: true,
|
||||||
|
// required: true,
|
||||||
|
// enableDecimal: true,
|
||||||
|
// ),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
MIHNumberField(
|
MihTextFormField(
|
||||||
|
fillColor:
|
||||||
|
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||||
|
inputColor:
|
||||||
|
MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
||||||
controller: tipPercentageController,
|
controller: tipPercentageController,
|
||||||
hintText: "Tip %",
|
multiLineInput: false,
|
||||||
editable: true,
|
requiredText: true,
|
||||||
required: true,
|
hintText: "Tip Percentage",
|
||||||
enableDecimal: false,
|
numberMode: true,
|
||||||
|
validator: (value) {
|
||||||
|
return MihValidationServices().isEmpty(value);
|
||||||
|
},
|
||||||
),
|
),
|
||||||
const SizedBox(height: 10),
|
// MIHNumberField(
|
||||||
|
// controller: tipPercentageController,
|
||||||
|
// hintText: "Tip %",
|
||||||
|
// editable: true,
|
||||||
|
// required: true,
|
||||||
|
// enableDecimal: false,
|
||||||
|
// ),
|
||||||
|
const SizedBox(height: 20),
|
||||||
MIHDropdownField(
|
MIHDropdownField(
|
||||||
controller: splitBillController,
|
controller: splitBillController,
|
||||||
hintText: "Split Bill",
|
hintText: "Split Bill",
|
||||||
@@ -302,39 +311,69 @@ class _TipCalcState extends State<TipCalc> {
|
|||||||
ValueListenableBuilder(
|
ValueListenableBuilder(
|
||||||
valueListenable: splitValue,
|
valueListenable: splitValue,
|
||||||
builder: (BuildContext context, String value, Widget? child) {
|
builder: (BuildContext context, String value, Widget? child) {
|
||||||
|
temp = value;
|
||||||
return Visibility(
|
return Visibility(
|
||||||
visible: value == "Yes",
|
visible: temp == "Yes",
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
MIHNumberField(
|
MihTextFormField(
|
||||||
|
fillColor: MzanziInnovationHub.of(context)!
|
||||||
|
.theme
|
||||||
|
.secondaryColor(),
|
||||||
|
inputColor: MzanziInnovationHub.of(context)!
|
||||||
|
.theme
|
||||||
|
.primaryColor(),
|
||||||
controller: noPeopleController,
|
controller: noPeopleController,
|
||||||
|
multiLineInput: false,
|
||||||
|
requiredText: temp == "Yes",
|
||||||
hintText: "No. of People",
|
hintText: "No. of People",
|
||||||
editable: true,
|
numberMode: true,
|
||||||
required: true,
|
validator: (validationValue) {
|
||||||
enableDecimal: false,
|
if (temp == "Yes") {
|
||||||
|
return MihValidationServices()
|
||||||
|
.isEmpty(validationValue);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
},
|
||||||
),
|
),
|
||||||
|
// MIHNumberField(
|
||||||
|
// controller: noPeopleController,
|
||||||
|
// hintText: "No. of People",
|
||||||
|
// editable: true,
|
||||||
|
// required: true,
|
||||||
|
// enableDecimal: false,
|
||||||
|
// ),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
Wrap(
|
const SizedBox(height: 10),
|
||||||
|
Center(
|
||||||
|
child: Wrap(
|
||||||
spacing: 10,
|
spacing: 10,
|
||||||
runSpacing: 10,
|
runSpacing: 10,
|
||||||
children: [
|
children: [
|
||||||
MihButton(
|
MihButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
|
if (_formKey.currentState!.validate()) {
|
||||||
validateInput();
|
validateInput();
|
||||||
|
} else {
|
||||||
|
MihAlertServices().formNotFilledCompletely(context);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
buttonColor:
|
buttonColor: MzanziInnovationHub.of(context)!
|
||||||
MzanziInnovationHub.of(context)!.theme.successColor(),
|
.theme
|
||||||
|
.successColor(),
|
||||||
width: 300,
|
width: 300,
|
||||||
child: Text(
|
child: Text(
|
||||||
"Calculate",
|
"Calculate",
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color:
|
color: MzanziInnovationHub.of(context)!
|
||||||
MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
.theme
|
||||||
|
.primaryColor(),
|
||||||
fontSize: 20,
|
fontSize: 20,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
),
|
),
|
||||||
@@ -350,8 +389,9 @@ class _TipCalcState extends State<TipCalc> {
|
|||||||
child: Text(
|
child: Text(
|
||||||
"Clear",
|
"Clear",
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color:
|
color: MzanziInnovationHub.of(context)!
|
||||||
MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
.theme
|
||||||
|
.primaryColor(),
|
||||||
fontSize: 20,
|
fontSize: 20,
|
||||||
fontWeight: FontWeight.bold,
|
fontWeight: FontWeight.bold,
|
||||||
),
|
),
|
||||||
@@ -359,8 +399,12 @@ class _TipCalcState extends State<TipCalc> {
|
|||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user