import 'package:flutter/material.
dart';
import 'package:scientific_calculator/[Link]';
void main() {
runApp(MaterialApp(
home: CalculatorApp() ,
));
}
class CalculatorApp extends StatefulWidget {
const CalculatorApp({[Link]});
@override
State<CalculatorApp> createState() => _CalculatorAppState();
}
class _CalculatorAppState extends State<CalculatorApp> {
//variables
double firstNumber = 0.0;
double secondNumber = 0.0;
var input = " ";
var output = " ";
var operation = " ";
var hideInput = false;
var outputSize = 34.0;
onButtonClick(value){
//if value AC
if(value == "AC"){
var input = " ";
var output = " ";
}else if(value == "<"){
if([Link]) {
input = [Link](0, [Link] - 1);
}
}else if(value == "="){
if([Link]) {
var userInput = input;
userInput = [Link]("x", "*");
Parser p = Parser();
Expression expression = [Link](userInput);
ContextModel cm = ContextModel();
var finalValue = [Link](EvaluationType, cm);
output = [Link]();
if([Link](".0")) {
output = [Link](0, [Link] - 2);
}
input = output;
hideInput = true ;
outputSize = 52;
}
}else{
input = input + value;
hideInput = false ;
outputSize = 34;
}
setState(() {});
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: [Link],
body: Column(
children: [
//input-output area
Expanded(child: Container(
width: [Link],
padding: const [Link](12),
child: Column(
mainAxisAlignment: [Link],
crossAxisAlignment: [Link],
children: [
Text(
hideInput ? '': input,
style: TextStyle(
fontSize: 45,
color: [Link],
),
),
const SizedBox(
height: 20,
),
Text(
output, style: TextStyle(
fontSize: 35,
color: [Link],
),
),
const SizedBox(
height: 30,
),
],
),
)),
//buttons space
Row(
children: [
button(text: "√"),
button(text: "x²"),
button(text: "ln"),
button(text: "( )"),
],
),
Row(
children: [
button(text: "sin"),
button(text: "cos"),
button(text: "tan"),
button(text: "log"),
],
),
Row(
children: [
button(text: "AC",buttonBgColor: operatorColor,
tColor: [Link]),
button(text: "<",buttonBgColor: operatorColor,
tColor: [Link]),
button(text: "%",buttonBgColor: operatorColor,
tColor: [Link]),
button(text: "/",buttonBgColor: operatorColor,
tColor: [Link]),
],
),
Row(
children: [
button(text: "7"),
button(text: "8"),
button(text: "9"),
button(text: "x",buttonBgColor: operatorColor,
tColor: [Link]),
],
),
Row(
children: [
button(text: "4"),
button(text: "5"),
button(text: "6"),
button(text: "+",buttonBgColor: operatorColor,
tColor: [Link]),
],
),
Row(
children: [
button(text: "3"),
button(text: "2"),
button(text: "1"),
button(text: "-",buttonBgColor: operatorColor,
tColor: [Link]),
],
),
Row(
children: [
button(text: "0"),
button(text: "."),
button(text: "EXP"),
button(text: "=",buttonBgColor: operatorColor,
tColor: [Link]),
],
),
],
),
);
}
Widget button({
text, tColor = [Link], buttonBgColor = buttonColor,
}){
return Expanded(
child: Container(
margin: const [Link](8),
child: ElevatedButton(
style: [Link](
shape: RoundedRectangleBorder(
borderRadius: [Link](12),
),
padding: [Link](22),
backgroundColor: buttonBgColor,
),
onPressed: () => onButtonClick(text),
child: Text(
text, style: TextStyle(
fontSize: 18,
color: tColor,
fontWeight: [Link],
),
),
),
),
);
}
extension on Expression {
evaluate(Type evaluationType, ContextModel cm) {}
}
class EvaluationType {
}
class ContextModel {
}
class Expression {
}
class Parser {
Expression parse(String userInput)
import 'package:flutter/[Link]';
import 'package:scientific_calculator/[Link]';
void main() {
runApp(MaterialApp(
home: CalculatorApp(),
));
}
class CalculatorApp extends StatefulWidget {
const CalculatorApp({Key? key}) : super(key: key);
@override
State<CalculatorApp> createState() => _CalculatorAppState();
}
class _CalculatorAppState extends State<CalculatorApp> {
// Variables
String input = "";
String output = "";
bool hideInput = false;
void onButtonClick(String value) {
if (value == "AC") {
input = "";
output = "";
} else if (value == "<") {
if ([Link]) {
input = [Link](0, [Link] - 1);
}
} else if (value == "=") {
if ([Link]) {
try {
var userInput = [Link]("x", "*"); // Replace 'x' with '*'
var Expression;
final expression = [Link](userInput);
final evaluator = const ExpressionEvaluator();
var finalValue = [Link](expression, null);
output = [Link]();
if ([Link](".0")) {
output = [Link](0, [Link] - 2);
}
input = output;
hideInput = true;
} catch (e) {
output = "Error"; // Handle parsing errors
}
}
} else {
input += value;
hideInput = false;
}
setState(() {});
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: [Link],
body: Column(
children: [
// Input-output area
Expanded(
child: Container(
width: [Link],
padding: const [Link](12),
child: Column(
mainAxisAlignment: [Link],
crossAxisAlignment: [Link],
children: [
Text(
hideInput ? '' : input,
style: TextStyle(
fontSize: 45,
color: [Link],
),
),
const SizedBox(height: 20),
Text(
output,
style: TextStyle(
fontSize: 35,
color: [Link],
),
),
const SizedBox(height: 30),
],
),
),
),
// Buttons space
Row(
children: [
button(text: "√"),
button(text: "x²"),
button(text: "ln"),
button(text: "( )"),
],
),
Row(
children: [
button(text: "sin"),
button(text: "cos"),
button(text: "tan"),
button(text: "log"),
],
),
Row(
children: [
button(text: "AC", buttonBgColor: [Link]),
button(text: "<", buttonBgColor: [Link]),
button(text: "%", buttonBgColor: [Link]),
button(text: "/", buttonBgColor: [Link]),
],
),
Row(
children: [
button(text: "7"),
button(text: "8"),
button(text: "9"),
button(text: "x", buttonBgColor: [Link]),
],
),
Row(
children: [
button(text: "4"),
button(text: "5"),
button(text: "6"),
button(text: "+", buttonBgColor: [Link]),
],
),
Row(
children: [
button(text: "3"),
button(text: "2"),
button(text: "1"),
button(text: "-", buttonBgColor: [Link]),
],
),
Row(
children: [
button(text: "0"),
button(text: "."),
button(text: "EXP"),
button(text: "=", buttonBgColor: [Link]),
],
),
],
),
);
}
Widget button({required String text, Color tColor = [Link], Color
buttonBgColor = Colors.black45}) {
return Expanded(
child: Container(
margin: const [Link](8),
child: ElevatedButton(
style: [Link](
shape: RoundedRectangleBorder(
borderRadius: [Link](12),
),
padding: const [Link](22),
backgroundColor: buttonBgColor,
),
onPressed: () => onButtonClick(text),
child: Text(
text,
style: TextStyle(
fontSize: 18,
color: tColor,
fontWeight: [Link],
),
),
),
),
);
}
}
class ExpressionEvaluator {
const ExpressionEvaluator();
eval(expression, param1) {}
}