File tree 3 files changed +21
-0
lines changed
3 files changed +21
-0
lines changed Original file line number Diff line number Diff line change 1
1
import 'package:flutter/material.dart' ;
2
+ import 'package:math_expressions/math_expressions.dart' ;
2
3
3
4
void main (){
4
5
runApp (Calculator ());
@@ -46,6 +47,17 @@ class _SimpleCalculatorState extends State<SimpleCalculator> {
46
47
}else if (buttonText == "=" ){
47
48
equationFontSize = 38.0 ;
48
49
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
+ }
49
61
}else {
50
62
equationFontSize = 48.0 ;
51
63
resultFontSize = 38.0 ;
Original file line number Diff line number Diff line change @@ -88,6 +88,13 @@ packages:
88
88
url: "https://pub.dartlang.org"
89
89
source: hosted
90
90
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"
91
98
meta:
92
99
dependency: transitive
93
100
description:
Original file line number Diff line number Diff line change @@ -20,9 +20,11 @@ dependencies:
20
20
flutter :
21
21
sdk : flutter
22
22
23
+
23
24
# The following adds the Cupertino Icons font to your application.
24
25
# Use with the CupertinoIcons class for iOS style icons.
25
26
cupertino_icons : ^0.1.2
27
+ math_expressions : ^2.0.0
26
28
27
29
dev_dependencies :
28
30
flutter_test :
You can’t perform that action at this time.
0 commit comments