Merge pull request #100 from yaso-meth/NEW--Calculator-reDesign
Calculator Redesign
This commit is contained in:
304
Frontend/lib/mih_packages/calculator/app_tools/simple_calc.dart
Normal file
304
Frontend/lib/mih_packages/calculator/app_tools/simple_calc.dart
Normal file
@@ -0,0 +1,304 @@
|
|||||||
|
import 'package:Mzansi_Innovation_Hub/main.dart';
|
||||||
|
import 'package:Mzansi_Innovation_Hub/mih_components/mih_inputs_and_buttons/mih_button.dart';
|
||||||
|
import 'package:Mzansi_Innovation_Hub/mih_components/mih_package/mih-app_tool_body.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:math_expressions/math_expressions.dart';
|
||||||
|
|
||||||
|
class SimpleCalc extends StatefulWidget {
|
||||||
|
const SimpleCalc({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<SimpleCalc> createState() => _SimpleCalcState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _SimpleCalcState extends State<SimpleCalc> {
|
||||||
|
var userInput = '';
|
||||||
|
var answer = '0';
|
||||||
|
|
||||||
|
// Array of button
|
||||||
|
final List<String> buttons = [
|
||||||
|
'C',
|
||||||
|
'(',
|
||||||
|
')',
|
||||||
|
'D',
|
||||||
|
'7',
|
||||||
|
'8',
|
||||||
|
'9',
|
||||||
|
'/',
|
||||||
|
'4',
|
||||||
|
'5',
|
||||||
|
'6',
|
||||||
|
'x',
|
||||||
|
'1',
|
||||||
|
'2',
|
||||||
|
'3',
|
||||||
|
'-',
|
||||||
|
'0',
|
||||||
|
'.',
|
||||||
|
'=',
|
||||||
|
'+',
|
||||||
|
];
|
||||||
|
|
||||||
|
// function to calculate the input operation
|
||||||
|
void equalPressed() {
|
||||||
|
String finaluserinput = userInput;
|
||||||
|
finaluserinput = userInput.replaceAll('x', '*');
|
||||||
|
|
||||||
|
Parser p = Parser();
|
||||||
|
Expression exp = p.parse(finaluserinput);
|
||||||
|
ContextModel cm = ContextModel();
|
||||||
|
double eval = exp.evaluate(EvaluationType.REAL, cm);
|
||||||
|
answer = eval.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return MihAppToolBody(
|
||||||
|
borderOn: false,
|
||||||
|
bodyItem: getBody(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget getBody() {
|
||||||
|
double width = MediaQuery.sizeOf(context).width;
|
||||||
|
double height = MediaQuery.sizeOf(context).height;
|
||||||
|
var padding = MediaQuery.paddingOf(context);
|
||||||
|
double newheight = height - padding.top - padding.bottom;
|
||||||
|
print("width: $width");
|
||||||
|
print("height: $height");
|
||||||
|
print("newheight: $newheight");
|
||||||
|
double calcWidth = 500;
|
||||||
|
if (MzanziInnovationHub.of(context)!.theme.screenType == "desktop") {
|
||||||
|
if (height < 700) {
|
||||||
|
calcWidth = 300;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.all(10.0),
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: <Widget>[
|
||||||
|
Text(
|
||||||
|
"Simple Calculator",
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 25,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Divider(
|
||||||
|
color: MzanziInnovationHub.of(context)!.theme.secondaryColor()),
|
||||||
|
const SizedBox(height: 10),
|
||||||
|
Container(
|
||||||
|
//color: Colors.white,
|
||||||
|
padding: const EdgeInsets.all(20),
|
||||||
|
alignment: Alignment.centerRight,
|
||||||
|
child: Text(
|
||||||
|
userInput,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 18,
|
||||||
|
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Container(
|
||||||
|
width: double.infinity,
|
||||||
|
//color: Colors.white,
|
||||||
|
padding: const EdgeInsets.all(15),
|
||||||
|
alignment: Alignment.centerRight,
|
||||||
|
child: Text(
|
||||||
|
answer,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 30,
|
||||||
|
color:
|
||||||
|
MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||||
|
fontWeight: FontWeight.bold),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Container(
|
||||||
|
alignment: Alignment.centerRight,
|
||||||
|
child: SizedBox(
|
||||||
|
width: calcWidth,
|
||||||
|
child: GridView.builder(
|
||||||
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
|
shrinkWrap: true,
|
||||||
|
// padding: EdgeInsets.only(
|
||||||
|
// left: width / 10,
|
||||||
|
// right: width / 10,
|
||||||
|
// bottom: height / 15,
|
||||||
|
// //top: 20,
|
||||||
|
// ),
|
||||||
|
// shrinkWrap: true,
|
||||||
|
itemCount: buttons.length,
|
||||||
|
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||||
|
crossAxisCount: 4,
|
||||||
|
//mainAxisExtent: 150,
|
||||||
|
),
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
// Clear Button
|
||||||
|
if (index == 0) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.all(4.0),
|
||||||
|
child: MIHButton(
|
||||||
|
onTap: () {
|
||||||
|
setState(() {
|
||||||
|
userInput = '';
|
||||||
|
answer = '0';
|
||||||
|
});
|
||||||
|
},
|
||||||
|
buttonText: buttons[index],
|
||||||
|
buttonColor: MzanziInnovationHub.of(context)!
|
||||||
|
.theme
|
||||||
|
.messageTextColor(),
|
||||||
|
textColor: MzanziInnovationHub.of(context)!
|
||||||
|
.theme
|
||||||
|
.primaryColor(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// +/- button
|
||||||
|
else if (index == 1) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.all(4.0),
|
||||||
|
child: MIHButton(
|
||||||
|
onTap: () {
|
||||||
|
setState(() {
|
||||||
|
userInput += buttons[index];
|
||||||
|
});
|
||||||
|
},
|
||||||
|
buttonText: buttons[index],
|
||||||
|
buttonColor: MzanziInnovationHub.of(context)!
|
||||||
|
.theme
|
||||||
|
.messageTextColor(),
|
||||||
|
textColor: MzanziInnovationHub.of(context)!
|
||||||
|
.theme
|
||||||
|
.primaryColor(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// % Button
|
||||||
|
else if (index == 2) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.all(4.0),
|
||||||
|
child: MIHButton(
|
||||||
|
onTap: () {
|
||||||
|
setState(() {
|
||||||
|
userInput += buttons[index];
|
||||||
|
});
|
||||||
|
},
|
||||||
|
buttonText: buttons[index],
|
||||||
|
buttonColor: MzanziInnovationHub.of(context)!
|
||||||
|
.theme
|
||||||
|
.messageTextColor(),
|
||||||
|
textColor: MzanziInnovationHub.of(context)!
|
||||||
|
.theme
|
||||||
|
.primaryColor(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// Delete Button
|
||||||
|
else if (index == 3) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.all(4.0),
|
||||||
|
child: MIHButton(
|
||||||
|
onTap: () {
|
||||||
|
setState(() {
|
||||||
|
userInput =
|
||||||
|
userInput.substring(0, userInput.length - 1);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
buttonText: buttons[index],
|
||||||
|
buttonColor:
|
||||||
|
MzanziInnovationHub.of(context)!.theme.errorColor(),
|
||||||
|
textColor: MzanziInnovationHub.of(context)!
|
||||||
|
.theme
|
||||||
|
.primaryColor(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// Equal_to Button
|
||||||
|
else if (index == 18) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.all(4.0),
|
||||||
|
child: MIHButton(
|
||||||
|
onTap: () {
|
||||||
|
setState(() {
|
||||||
|
equalPressed();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
buttonText: buttons[index],
|
||||||
|
buttonColor: MzanziInnovationHub.of(context)!
|
||||||
|
.theme
|
||||||
|
.successColor(),
|
||||||
|
textColor: MzanziInnovationHub.of(context)!
|
||||||
|
.theme
|
||||||
|
.primaryColor(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// +, -, / x buttons
|
||||||
|
else if (index == 7 ||
|
||||||
|
index == 11 ||
|
||||||
|
index == 15 ||
|
||||||
|
index == 19) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.all(4.0),
|
||||||
|
child: MIHButton(
|
||||||
|
onTap: () {
|
||||||
|
if (answer == "0") {
|
||||||
|
setState(() {
|
||||||
|
userInput += buttons[index];
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
setState(() {
|
||||||
|
userInput = answer;
|
||||||
|
answer = "0";
|
||||||
|
userInput += buttons[index];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// setState(() {
|
||||||
|
// userInput += buttons[index];
|
||||||
|
// });
|
||||||
|
},
|
||||||
|
buttonText: buttons[index],
|
||||||
|
buttonColor: MzanziInnovationHub.of(context)!
|
||||||
|
.theme
|
||||||
|
.messageTextColor(),
|
||||||
|
textColor: MzanziInnovationHub.of(context)!
|
||||||
|
.theme
|
||||||
|
.primaryColor(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// other buttons
|
||||||
|
else {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.all(4.0),
|
||||||
|
child: MIHButton(
|
||||||
|
onTap: () {
|
||||||
|
setState(() {
|
||||||
|
userInput += buttons[index];
|
||||||
|
});
|
||||||
|
},
|
||||||
|
buttonText: buttons[index],
|
||||||
|
buttonColor: MzanziInnovationHub.of(context)!
|
||||||
|
.theme
|
||||||
|
.secondaryColor(),
|
||||||
|
textColor: MzanziInnovationHub.of(context)!
|
||||||
|
.theme
|
||||||
|
.primaryColor(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ import 'package:Mzansi_Innovation_Hub/mih_components/mih_inputs_and_buttons/mih_
|
|||||||
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_inputs_and_buttons/mih_number_input.dart';
|
||||||
import 'package:Mzansi_Innovation_Hub/mih_components/mih_layout/mih_window.dart';
|
import 'package:Mzansi_Innovation_Hub/mih_components/mih_layout/mih_window.dart';
|
||||||
|
import 'package:Mzansi_Innovation_Hub/mih_components/mih_package/mih-app_tool_body.dart';
|
||||||
import 'package:Mzansi_Innovation_Hub/mih_components/mih_pop_up_messages/mih_error_message.dart';
|
import 'package:Mzansi_Innovation_Hub/mih_components/mih_pop_up_messages/mih_error_message.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';
|
||||||
@@ -260,91 +261,103 @@ class _TipCalcState extends State<TipCalc> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Column(
|
return MihAppToolBody(
|
||||||
mainAxisSize: MainAxisSize.max,
|
borderOn: false,
|
||||||
children: <Widget>[
|
bodyItem: getBody(),
|
||||||
Text(
|
);
|
||||||
"Tip Calculator",
|
}
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style: TextStyle(
|
Widget getBody() {
|
||||||
fontSize: 25,
|
return Padding(
|
||||||
fontWeight: FontWeight.bold,
|
padding: const EdgeInsets.all(10.0),
|
||||||
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.max,
|
||||||
|
children: <Widget>[
|
||||||
|
Text(
|
||||||
|
"Tip Calculator",
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 25,
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
Divider(
|
||||||
Divider(color: MzanziInnovationHub.of(context)!.theme.secondaryColor()),
|
color: MzanziInnovationHub.of(context)!.theme.secondaryColor()),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
MIHNumberField(
|
MIHNumberField(
|
||||||
controller: billAmountController,
|
controller: billAmountController,
|
||||||
hintText: "Bill Amount",
|
hintText: "Bill Amount",
|
||||||
editable: true,
|
editable: true,
|
||||||
required: true,
|
required: true,
|
||||||
enableDecimal: true,
|
enableDecimal: true,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
MIHNumberField(
|
MIHNumberField(
|
||||||
controller: tipPercentageController,
|
controller: tipPercentageController,
|
||||||
hintText: "Tip %",
|
hintText: "Tip %",
|
||||||
editable: true,
|
editable: true,
|
||||||
required: true,
|
required: true,
|
||||||
enableDecimal: false,
|
enableDecimal: false,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
MIHDropdownField(
|
MIHDropdownField(
|
||||||
controller: splitBillController,
|
controller: splitBillController,
|
||||||
hintText: "Split Bill",
|
hintText: "Split Bill",
|
||||||
dropdownOptions: const ["Yes", "No"],
|
dropdownOptions: const ["Yes", "No"],
|
||||||
required: true,
|
required: true,
|
||||||
editable: true,
|
editable: true,
|
||||||
enableSearch: false,
|
enableSearch: false,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
ValueListenableBuilder(
|
ValueListenableBuilder(
|
||||||
valueListenable: splitValue,
|
valueListenable: splitValue,
|
||||||
builder: (BuildContext context, String value, Widget? child) {
|
builder: (BuildContext context, String value, Widget? child) {
|
||||||
return Visibility(
|
return Visibility(
|
||||||
visible: value == "Yes",
|
visible: value == "Yes",
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
MIHNumberField(
|
MIHNumberField(
|
||||||
controller: noPeopleController,
|
controller: noPeopleController,
|
||||||
hintText: "No. of People",
|
hintText: "No. of People",
|
||||||
editable: true,
|
editable: true,
|
||||||
required: true,
|
required: true,
|
||||||
enableDecimal: false,
|
enableDecimal: false,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 10),
|
const SizedBox(height: 10),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
|
||||||
),
|
|
||||||
SizedBox(
|
|
||||||
width: double.infinity,
|
|
||||||
height: 50,
|
|
||||||
child: MIHButton(
|
|
||||||
onTap: () {
|
|
||||||
validateInput();
|
|
||||||
},
|
},
|
||||||
buttonText: "Calculate",
|
|
||||||
buttonColor: MzanziInnovationHub.of(context)!.theme.successColor(),
|
|
||||||
textColor: MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
|
||||||
),
|
),
|
||||||
),
|
SizedBox(
|
||||||
const SizedBox(height: 10),
|
width: double.infinity,
|
||||||
SizedBox(
|
height: 50,
|
||||||
width: double.infinity,
|
child: MIHButton(
|
||||||
height: 50,
|
onTap: () {
|
||||||
child: MIHButton(
|
validateInput();
|
||||||
onTap: () {
|
},
|
||||||
clearInput();
|
buttonText: "Calculate",
|
||||||
},
|
buttonColor:
|
||||||
buttonText: "Clear",
|
MzanziInnovationHub.of(context)!.theme.successColor(),
|
||||||
buttonColor: MzanziInnovationHub.of(context)!.theme.errorColor(),
|
textColor: MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
||||||
textColor: MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
),
|
||||||
),
|
),
|
||||||
),
|
const SizedBox(height: 10),
|
||||||
],
|
SizedBox(
|
||||||
|
width: double.infinity,
|
||||||
|
height: 50,
|
||||||
|
child: MIHButton(
|
||||||
|
onTap: () {
|
||||||
|
clearInput();
|
||||||
|
},
|
||||||
|
buttonText: "Clear",
|
||||||
|
buttonColor: MzanziInnovationHub.of(context)!.theme.errorColor(),
|
||||||
|
textColor: MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,9 @@
|
|||||||
import 'package:Mzansi_Innovation_Hub/mih_components/mih_layout/mih_action.dart';
|
import 'package:Mzansi_Innovation_Hub/mih_components/mih_package/mih_app.dart';
|
||||||
import 'package:Mzansi_Innovation_Hub/mih_components/mih_layout/mih_body.dart';
|
import 'package:Mzansi_Innovation_Hub/mih_components/mih_package/mih_app_action.dart';
|
||||||
import 'package:Mzansi_Innovation_Hub/mih_components/mih_layout/mih_header.dart';
|
import 'package:Mzansi_Innovation_Hub/mih_components/mih_package/mih_app_tools.dart';
|
||||||
import 'package:Mzansi_Innovation_Hub/mih_components/mih_layout/mih_layout_builder.dart';
|
import 'package:Mzansi_Innovation_Hub/mih_packages/calculator/app_tools/simple_calc.dart';
|
||||||
import 'package:Mzansi_Innovation_Hub/mih_objects/arguments.dart';
|
import 'package:Mzansi_Innovation_Hub/mih_packages/calculator/app_tools/tip_calc.dart';
|
||||||
import 'package:Mzansi_Innovation_Hub/mih_packages/calculator/simple_calc.dart';
|
|
||||||
import 'package:Mzansi_Innovation_Hub/mih_packages/calculator/tip_calc.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_swipe_detector/flutter_swipe_detector.dart';
|
|
||||||
|
|
||||||
class MIHCalculator extends StatefulWidget {
|
class MIHCalculator extends StatefulWidget {
|
||||||
final bool personalSelected;
|
final bool personalSelected;
|
||||||
@@ -22,177 +19,55 @@ class MIHCalculator extends StatefulWidget {
|
|||||||
class _MIHCalculatorState extends State<MIHCalculator> {
|
class _MIHCalculatorState extends State<MIHCalculator> {
|
||||||
int _selectedIndex = 0;
|
int _selectedIndex = 0;
|
||||||
|
|
||||||
MIHAction getActionButton() {
|
@override
|
||||||
return MIHAction(
|
Widget build(BuildContext context) {
|
||||||
|
return MihApp(
|
||||||
|
appActionButton: getAction(),
|
||||||
|
appTools: getTools(),
|
||||||
|
appBody: getToolBody(),
|
||||||
|
selectedbodyIndex: _selectedIndex,
|
||||||
|
onIndexChange: (newValue) {
|
||||||
|
setState(() {
|
||||||
|
_selectedIndex = newValue;
|
||||||
|
});
|
||||||
|
print("Index: $_selectedIndex");
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
MihAppAction getAction() {
|
||||||
|
return MihAppAction(
|
||||||
icon: const Icon(Icons.arrow_back),
|
icon: const Icon(Icons.arrow_back),
|
||||||
iconSize: 35,
|
iconSize: 35,
|
||||||
onTap: () {
|
onTap: () {
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
Navigator.of(context).popAndPushNamed(
|
|
||||||
'/',
|
|
||||||
arguments: AuthArguments(widget.personalSelected, false),
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
MIHHeader getHeader() {
|
MihAppTools getTools() {
|
||||||
return const MIHHeader(
|
Map<Widget, void Function()?> temp = {};
|
||||||
headerAlignment: MainAxisAlignment.center,
|
temp[const Icon(Icons.calculate)] = () {
|
||||||
headerItems: [
|
setState(() {
|
||||||
Text(
|
_selectedIndex = 0;
|
||||||
"",
|
});
|
||||||
style: TextStyle(
|
};
|
||||||
fontWeight: FontWeight.bold,
|
temp[const Icon(Icons.money)] = () {
|
||||||
fontSize: 25,
|
setState(() {
|
||||||
),
|
_selectedIndex = 1;
|
||||||
),
|
});
|
||||||
],
|
};
|
||||||
|
return MihAppTools(
|
||||||
|
tools: temp,
|
||||||
|
selcetedIndex: _selectedIndex,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
MIHHeader getSecAction() {
|
List<Widget> getToolBody() {
|
||||||
return MIHHeader(
|
List<Widget> toolBodies = [
|
||||||
headerAlignment: MainAxisAlignment.end,
|
const SimpleCalc(),
|
||||||
headerItems: [
|
const TipCalc(),
|
||||||
//============ Simple Calc ================
|
];
|
||||||
Visibility(
|
return toolBodies;
|
||||||
visible: _selectedIndex != 0,
|
|
||||||
child: IconButton(
|
|
||||||
onPressed: () {
|
|
||||||
setState(() {
|
|
||||||
_selectedIndex = 0;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
icon: const Icon(
|
|
||||||
Icons.calculate,
|
|
||||||
size: 35,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Visibility(
|
|
||||||
visible: _selectedIndex == 0,
|
|
||||||
child: IconButton.filled(
|
|
||||||
iconSize: 35,
|
|
||||||
onPressed: () {
|
|
||||||
setState(() {
|
|
||||||
_selectedIndex = 0;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
icon: const Icon(
|
|
||||||
Icons.calculate,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
//============ Tip Calc ================
|
|
||||||
Visibility(
|
|
||||||
visible: _selectedIndex != 1,
|
|
||||||
child: IconButton(
|
|
||||||
onPressed: () {
|
|
||||||
setState(() {
|
|
||||||
_selectedIndex = 1;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
icon: const Icon(
|
|
||||||
Icons.money,
|
|
||||||
size: 35,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Visibility(
|
|
||||||
visible: _selectedIndex == 1,
|
|
||||||
child: IconButton.filled(
|
|
||||||
onPressed: () {
|
|
||||||
setState(() {
|
|
||||||
_selectedIndex = 1;
|
|
||||||
});
|
|
||||||
},
|
|
||||||
icon: const Icon(
|
|
||||||
Icons.money,
|
|
||||||
size: 35,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
// //============ Patient Files ================
|
|
||||||
// Visibility(
|
|
||||||
// visible: _selectedIndex != 2,
|
|
||||||
// child: IconButton(
|
|
||||||
// onPressed: () {
|
|
||||||
// setState(() {
|
|
||||||
// _selectedIndex = 2;
|
|
||||||
// });
|
|
||||||
// },
|
|
||||||
// icon: const Icon(
|
|
||||||
// Icons.file_present,
|
|
||||||
// size: 35,
|
|
||||||
// ),
|
|
||||||
// ),
|
|
||||||
// ),
|
|
||||||
// Visibility(
|
|
||||||
// visible: _selectedIndex == 2,
|
|
||||||
// child: IconButton.filled(
|
|
||||||
// onPressed: () {
|
|
||||||
// setState(() {
|
|
||||||
// _selectedIndex = 2;
|
|
||||||
// });
|
|
||||||
// },
|
|
||||||
// icon: const Icon(
|
|
||||||
// Icons.file_present,
|
|
||||||
// size: 35,
|
|
||||||
// ),
|
|
||||||
// ),
|
|
||||||
// ),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
MIHBody getBody() {
|
|
||||||
return MIHBody(
|
|
||||||
borderOn: true,
|
|
||||||
bodyItems: [showSelection(_selectedIndex)],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget showSelection(int index) {
|
|
||||||
if (index == 0) {
|
|
||||||
return const SimpleCalc();
|
|
||||||
} else if (index == 1) {
|
|
||||||
return const TipCalc();
|
|
||||||
} else {
|
|
||||||
return const Placeholder();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return SwipeDetector(
|
|
||||||
onSwipeLeft: (offset) {
|
|
||||||
if (_selectedIndex < 1) {
|
|
||||||
setState(() {
|
|
||||||
_selectedIndex += 1;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
//print("swipe left");
|
|
||||||
},
|
|
||||||
onSwipeRight: (offset) {
|
|
||||||
if (_selectedIndex > 0) {
|
|
||||||
setState(() {
|
|
||||||
_selectedIndex -= 1;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
//print("swipe right");
|
|
||||||
},
|
|
||||||
child: MIHLayoutBuilder(
|
|
||||||
actionButton: getActionButton(),
|
|
||||||
header: getHeader(),
|
|
||||||
secondaryActionButton: getSecAction(),
|
|
||||||
body: getBody(),
|
|
||||||
actionDrawer: null,
|
|
||||||
secondaryActionDrawer: null,
|
|
||||||
bottomNavBar: null,
|
|
||||||
pullDownToRefresh: false,
|
|
||||||
onPullDown: () async {},
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,283 +0,0 @@
|
|||||||
import 'package:Mzansi_Innovation_Hub/main.dart';
|
|
||||||
import 'package:Mzansi_Innovation_Hub/mih_components/mih_inputs_and_buttons/mih_button.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:math_expressions/math_expressions.dart';
|
|
||||||
|
|
||||||
class SimpleCalc extends StatefulWidget {
|
|
||||||
const SimpleCalc({super.key});
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<SimpleCalc> createState() => _SimpleCalcState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _SimpleCalcState extends State<SimpleCalc> {
|
|
||||||
var userInput = '';
|
|
||||||
var answer = '0';
|
|
||||||
|
|
||||||
// Array of button
|
|
||||||
final List<String> buttons = [
|
|
||||||
'C',
|
|
||||||
'(',
|
|
||||||
')',
|
|
||||||
'D',
|
|
||||||
'7',
|
|
||||||
'8',
|
|
||||||
'9',
|
|
||||||
'/',
|
|
||||||
'4',
|
|
||||||
'5',
|
|
||||||
'6',
|
|
||||||
'x',
|
|
||||||
'1',
|
|
||||||
'2',
|
|
||||||
'3',
|
|
||||||
'-',
|
|
||||||
'0',
|
|
||||||
'.',
|
|
||||||
'=',
|
|
||||||
'+',
|
|
||||||
];
|
|
||||||
|
|
||||||
// function to calculate the input operation
|
|
||||||
void equalPressed() {
|
|
||||||
String finaluserinput = userInput;
|
|
||||||
finaluserinput = userInput.replaceAll('x', '*');
|
|
||||||
|
|
||||||
Parser p = Parser();
|
|
||||||
Expression exp = p.parse(finaluserinput);
|
|
||||||
ContextModel cm = ContextModel();
|
|
||||||
double eval = exp.evaluate(EvaluationType.REAL, cm);
|
|
||||||
answer = eval.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
double width = MediaQuery.sizeOf(context).width;
|
|
||||||
double height = MediaQuery.sizeOf(context).height;
|
|
||||||
var padding = MediaQuery.paddingOf(context);
|
|
||||||
double newheight = height - padding.top - padding.bottom;
|
|
||||||
print("width: $width");
|
|
||||||
print("height: $height");
|
|
||||||
print("newheight: $newheight");
|
|
||||||
double calcWidth = 500;
|
|
||||||
if (MzanziInnovationHub.of(context)!.theme.screenType == "desktop") {
|
|
||||||
if (height < 700) {
|
|
||||||
calcWidth = 300;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Column(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.end,
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: <Widget>[
|
|
||||||
Text(
|
|
||||||
"Simple Calculator",
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 25,
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Divider(color: MzanziInnovationHub.of(context)!.theme.secondaryColor()),
|
|
||||||
const SizedBox(height: 10),
|
|
||||||
Container(
|
|
||||||
//color: Colors.white,
|
|
||||||
padding: const EdgeInsets.all(20),
|
|
||||||
alignment: Alignment.centerRight,
|
|
||||||
child: Text(
|
|
||||||
userInput,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 18,
|
|
||||||
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Container(
|
|
||||||
width: double.infinity,
|
|
||||||
//color: Colors.white,
|
|
||||||
padding: const EdgeInsets.all(15),
|
|
||||||
alignment: Alignment.centerRight,
|
|
||||||
child: Text(
|
|
||||||
answer,
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 30,
|
|
||||||
color: MzanziInnovationHub.of(context)!.theme.secondaryColor(),
|
|
||||||
fontWeight: FontWeight.bold),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Container(
|
|
||||||
alignment: Alignment.centerRight,
|
|
||||||
child: SizedBox(
|
|
||||||
width: calcWidth,
|
|
||||||
child: GridView.builder(
|
|
||||||
physics: const NeverScrollableScrollPhysics(),
|
|
||||||
shrinkWrap: true,
|
|
||||||
// padding: EdgeInsets.only(
|
|
||||||
// left: width / 10,
|
|
||||||
// right: width / 10,
|
|
||||||
// bottom: height / 15,
|
|
||||||
// //top: 20,
|
|
||||||
// ),
|
|
||||||
// shrinkWrap: true,
|
|
||||||
itemCount: buttons.length,
|
|
||||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
|
||||||
crossAxisCount: 4,
|
|
||||||
//mainAxisExtent: 150,
|
|
||||||
),
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
// Clear Button
|
|
||||||
if (index == 0) {
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.all(4.0),
|
|
||||||
child: MIHButton(
|
|
||||||
onTap: () {
|
|
||||||
setState(() {
|
|
||||||
userInput = '';
|
|
||||||
answer = '0';
|
|
||||||
});
|
|
||||||
},
|
|
||||||
buttonText: buttons[index],
|
|
||||||
buttonColor: MzanziInnovationHub.of(context)!
|
|
||||||
.theme
|
|
||||||
.messageTextColor(),
|
|
||||||
textColor:
|
|
||||||
MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// +/- button
|
|
||||||
else if (index == 1) {
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.all(4.0),
|
|
||||||
child: MIHButton(
|
|
||||||
onTap: () {
|
|
||||||
setState(() {
|
|
||||||
userInput += buttons[index];
|
|
||||||
});
|
|
||||||
},
|
|
||||||
buttonText: buttons[index],
|
|
||||||
buttonColor: MzanziInnovationHub.of(context)!
|
|
||||||
.theme
|
|
||||||
.messageTextColor(),
|
|
||||||
textColor:
|
|
||||||
MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
// % Button
|
|
||||||
else if (index == 2) {
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.all(4.0),
|
|
||||||
child: MIHButton(
|
|
||||||
onTap: () {
|
|
||||||
setState(() {
|
|
||||||
userInput += buttons[index];
|
|
||||||
});
|
|
||||||
},
|
|
||||||
buttonText: buttons[index],
|
|
||||||
buttonColor: MzanziInnovationHub.of(context)!
|
|
||||||
.theme
|
|
||||||
.messageTextColor(),
|
|
||||||
textColor:
|
|
||||||
MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
// Delete Button
|
|
||||||
else if (index == 3) {
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.all(4.0),
|
|
||||||
child: MIHButton(
|
|
||||||
onTap: () {
|
|
||||||
setState(() {
|
|
||||||
userInput =
|
|
||||||
userInput.substring(0, userInput.length - 1);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
buttonText: buttons[index],
|
|
||||||
buttonColor:
|
|
||||||
MzanziInnovationHub.of(context)!.theme.errorColor(),
|
|
||||||
textColor:
|
|
||||||
MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
// Equal_to Button
|
|
||||||
else if (index == 18) {
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.all(4.0),
|
|
||||||
child: MIHButton(
|
|
||||||
onTap: () {
|
|
||||||
setState(() {
|
|
||||||
equalPressed();
|
|
||||||
});
|
|
||||||
},
|
|
||||||
buttonText: buttons[index],
|
|
||||||
buttonColor:
|
|
||||||
MzanziInnovationHub.of(context)!.theme.successColor(),
|
|
||||||
textColor:
|
|
||||||
MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
// +, -, / x buttons
|
|
||||||
else if (index == 7 ||
|
|
||||||
index == 11 ||
|
|
||||||
index == 15 ||
|
|
||||||
index == 19) {
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.all(4.0),
|
|
||||||
child: MIHButton(
|
|
||||||
onTap: () {
|
|
||||||
if (answer == "0") {
|
|
||||||
setState(() {
|
|
||||||
userInput += buttons[index];
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
setState(() {
|
|
||||||
userInput = answer;
|
|
||||||
answer = "0";
|
|
||||||
userInput += buttons[index];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
// setState(() {
|
|
||||||
// userInput += buttons[index];
|
|
||||||
// });
|
|
||||||
},
|
|
||||||
buttonText: buttons[index],
|
|
||||||
buttonColor: MzanziInnovationHub.of(context)!
|
|
||||||
.theme
|
|
||||||
.messageTextColor(),
|
|
||||||
textColor:
|
|
||||||
MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
// other buttons
|
|
||||||
else {
|
|
||||||
return Padding(
|
|
||||||
padding: const EdgeInsets.all(4.0),
|
|
||||||
child: MIHButton(
|
|
||||||
onTap: () {
|
|
||||||
setState(() {
|
|
||||||
userInput += buttons[index];
|
|
||||||
});
|
|
||||||
},
|
|
||||||
buttonText: buttons[index],
|
|
||||||
buttonColor: MzanziInnovationHub.of(context)!
|
|
||||||
.theme
|
|
||||||
.secondaryColor(),
|
|
||||||
textColor:
|
|
||||||
MzanziInnovationHub.of(context)!.theme.primaryColor(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -12,12 +12,12 @@ import 'package:Mzansi_Innovation_Hub/mih_objects/business.dart';
|
|||||||
import 'package:Mzansi_Innovation_Hub/mih_objects/business_user.dart';
|
import 'package:Mzansi_Innovation_Hub/mih_objects/business_user.dart';
|
||||||
import 'package:Mzansi_Innovation_Hub/mih_packages/calendar/builder/build_appointment_list.dart';
|
import 'package:Mzansi_Innovation_Hub/mih_packages/calendar/builder/build_appointment_list.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import '../../main.dart';
|
import '../../../main.dart';
|
||||||
|
|
||||||
import '../../mih_components/mih_calendar.dart';
|
import '../../../mih_components/mih_calendar.dart';
|
||||||
import '../../mih_components/mih_pop_up_messages/mih_loading_circle.dart';
|
import '../../../mih_components/mih_pop_up_messages/mih_loading_circle.dart';
|
||||||
import '../../mih_env/env.dart';
|
import '../../../mih_env/env.dart';
|
||||||
import '../../mih_objects/app_user.dart';
|
import '../../../mih_objects/app_user.dart';
|
||||||
|
|
||||||
class Appointments extends StatefulWidget {
|
class Appointments extends StatefulWidget {
|
||||||
final AppUser signedInUser;
|
final AppUser signedInUser;
|
||||||
@@ -2,7 +2,7 @@ import 'package:Mzansi_Innovation_Hub/mih_components/mih_package/mih_app.dart';
|
|||||||
import 'package:Mzansi_Innovation_Hub/mih_components/mih_package/mih_app_action.dart';
|
import 'package:Mzansi_Innovation_Hub/mih_components/mih_package/mih_app_action.dart';
|
||||||
import 'package:Mzansi_Innovation_Hub/mih_components/mih_package/mih_app_tools.dart';
|
import 'package:Mzansi_Innovation_Hub/mih_components/mih_package/mih_app_tools.dart';
|
||||||
import 'package:Mzansi_Innovation_Hub/mih_objects/arguments.dart';
|
import 'package:Mzansi_Innovation_Hub/mih_objects/arguments.dart';
|
||||||
import 'package:Mzansi_Innovation_Hub/mih_packages/calendar/appointments.dart';
|
import 'package:Mzansi_Innovation_Hub/mih_packages/calendar/app_tools/appointments.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class MzansiCalendar extends StatefulWidget {
|
class MzansiCalendar extends StatefulWidget {
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ import 'package:Mzansi_Innovation_Hub/mih_components/mih_package/test/package_te
|
|||||||
import 'package:Mzansi_Innovation_Hub/mih_packages/about_mih/about_mih.dart';
|
import 'package:Mzansi_Innovation_Hub/mih_packages/about_mih/about_mih.dart';
|
||||||
import 'package:Mzansi_Innovation_Hub/mih_packages/about_mih/mih_policy_tos_ext/mih_privacy_polocy_external.dart';
|
import 'package:Mzansi_Innovation_Hub/mih_packages/about_mih/mih_policy_tos_ext/mih_privacy_polocy_external.dart';
|
||||||
import 'package:Mzansi_Innovation_Hub/mih_packages/about_mih/mih_policy_tos_ext/mih_terms_of_service_external.dart';
|
import 'package:Mzansi_Innovation_Hub/mih_packages/about_mih/mih_policy_tos_ext/mih_terms_of_service_external.dart';
|
||||||
import 'package:Mzansi_Innovation_Hub/mih_packages/calendar/mzansi_calendar.dart';
|
|
||||||
import 'package:Mzansi_Innovation_Hub/mih_packages/calculator/mih_calculator.dart';
|
import 'package:Mzansi_Innovation_Hub/mih_packages/calculator/mih_calculator.dart';
|
||||||
|
import 'package:Mzansi_Innovation_Hub/mih_packages/calendar/mzansi_calendar.dart';
|
||||||
import 'package:Mzansi_Innovation_Hub/mih_packages/mzansi_ai/mzansi_ai.dart';
|
import 'package:Mzansi_Innovation_Hub/mih_packages/mzansi_ai/mzansi_ai.dart';
|
||||||
import 'package:Mzansi_Innovation_Hub/mih_packages/mzansi_wallet/components/mih_barcode_scanner.dart';
|
import 'package:Mzansi_Innovation_Hub/mih_packages/mzansi_wallet/components/mih_barcode_scanner.dart';
|
||||||
import 'package:Mzansi_Innovation_Hub/mih_packages/mzansi_wallet/mih_wallet.dart';
|
import 'package:Mzansi_Innovation_Hub/mih_packages/mzansi_wallet/mih_wallet.dart';
|
||||||
|
|||||||
Reference in New Issue
Block a user