Skip to content

Commit ee050c0

Browse files
committed
app ready
1 parent acf7e35 commit ee050c0

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

lib/main.dart

+12
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:flutter/material.dart';
2+
import 'package:math_expressions/math_expressions.dart';
23

34
void main(){
45
runApp(Calculator());
@@ -46,6 +47,17 @@ class _SimpleCalculatorState extends State<SimpleCalculator> {
4647
}else if(buttonText == "="){
4748
equationFontSize = 38.0;
4849
resultFontSize = 48.0;
50+
expression = equation;
51+
expression = expression.replaceAll('x', '*');
52+
expression = expression.replaceAll('÷', '/');
53+
try{
54+
Parser p = Parser();
55+
Expression exp = p.parse(expression);
56+
ContextModel cm = ContextModel();
57+
result = '${exp.evaluate(EvaluationType.REAL, cm)}';
58+
}catch(e){
59+
result = "Error";
60+
}
4961
}else{
5062
equationFontSize = 48.0;
5163
resultFontSize = 38.0;

pubspec.lock

+7
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ packages:
8888
url: "https://pub.dartlang.org"
8989
source: hosted
9090
version: "0.12.6"
91+
math_expressions:
92+
dependency: "direct main"
93+
description:
94+
name: math_expressions
95+
url: "https://pub.dartlang.org"
96+
source: hosted
97+
version: "2.0.0"
9198
meta:
9299
dependency: transitive
93100
description:

pubspec.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ dependencies:
2020
flutter:
2121
sdk: flutter
2222

23+
2324
# The following adds the Cupertino Icons font to your application.
2425
# Use with the CupertinoIcons class for iOS style icons.
2526
cupertino_icons: ^0.1.2
27+
math_expressions: ^2.0.0
2628

2729
dev_dependencies:
2830
flutter_test:

0 commit comments

Comments
 (0)