Calculator Projects
Calculator Projects
at
Sathyabama Institute of Science and Technology
(Deemed to be University)
Submitted in partial fulfillment of the requirements for the award of Bachelor ofEngineering
Degree in Computer Science and Engineering specialization with Data Science
By
SCHOOL OF COMPUTING
SATHYABAMA
INSTITUTE OF SCIENCE AND TECHNOLOGY
(DEEMED TO BE UNIVERSITY)
Accredited with Grade “A” by NAAC
JEPPIAAR NAGAR, RAJIV GANDHISALAI,
CHENNAI – 600119
NOVEMBER – 2022
SATHYABAMA
INSTITUTE OF SCIENCE AND TECHNOLOGY
(DEEMED TO BE UNIVERSITY)
Accredited with Grade “A” by NAAC
(Established under Section 3 of UGC Act, 1956)
JEPPIAAR NAGAR, RAJIV GANDHI SALAI, CHENNAI– 600119
www.sathyabamauniversity.ac.in
BONAFIDE CERTIFICATE
This is to certify that this Project Report is the bonafide work of SANNE
HRUTHIKA SHETTY (40733025) who carried out the project entitled
“Calculator App using flutter” under my supervision from Aug 2022 to Oct
2022.
Internal Guide
Ms Nancy Kirupanithi.D
I SANNE HRUTHIKA SHETTY hereby declare that the Project Report entitled
and address) is submitted in partial fulfillment of the requirements for the award of Bachelor of
DATE: 12-09-2022
I would like to express my sincere and deep sense of gratitude to my Project Guide --------
--------------------for his valuable guidance, suggestions
andconstantencouragementpavedwayforthesuccessfulcompletionofmyprojectwork.
I wish to express my thanks to all Teaching and Non-teaching staff members of the
Department of Computer Science and Engineering whowerehelpfulinmanywaysfor
the completion of theproject.
TRAINING CERTIFICATE
ABSTRACT
This basic calculator app will combine a simple user interface, a few standard
operations and functions, and an output to display the result. So, it makes a great
starter application, or template for another basic app.
This work was centered on the Design and implementation of a simple scientific
calculator for education organization. The study traced calculator system as a tool to
completely change mathematical knowledge and sophisticated problems solving
strategies had advanced the field of simulated engine in mathematic. This project
work also focused principally on numbers and arithmetic operation. This researcher
investigated the manual system in detail with a view to finding out the need to
automate the system. Interestingly, the end result of simple calculator system was its
ability to process number and operators, and provides a useful result. Therefore, this
project will help immensely in the following way. Easy calculating of tedious
mathematical problems, easy to retrieval of errors and it will also be of a good
assistance to any researcher on these topics.
TABLE OF CONTENTS
1. Abstract
List of fig.
INTRODUCTION 12-20
1.1 Calculator 12
1.2 ER Diagram 12-13
1.3 Flutter Basics 14-16
1.4 Flutter Application Architecture 16-20
5.
5.1 Summary And Conclusion 42
LIST OF FIGURES
1.2.1 ER Diagram 12
1.5.2 Layers 18
1.5.3 Gestures 19
1.2 ER DIAGRAM
We’ll look at how to design and build a simple calculator app
with Dart and Flutter. The excellent features available in the Dart language and
Flutter SDK provide the modern developer with great a great platform for
quickly trying new ideas and building high performance apps.
This basic calculator app will combine a simple user interface, a few standard
operations and functions, and an output to display the result. So it makes a great
starter application, or template for another basic app.
The project for this app was initialized using flutter create, with no additional
packages or dependencies. All features are implemented with plain Dart and
Flutter in a clean and robust way.
Leveraging built-in language and SDK features allow the app architecture to be
kept as lean and efficient as possible. This translates into quicker project
turnaround, faster app binaries, and less technical debt.
To build this project, or create one like it, the following tools are required:
• Dart
• Flutter SDK
1.3 Flutter Basics
Flutter is Google’s Mobile SDK to build native iOS and Android, Desktop (Windows,
Linux, macOS), and Web apps from a single codebase. When
building applications with Flutter everything towards Widgets – the blocks with
which the flutter apps are built. They are structural elements that ship with a bunch
of material design-specific functionalities and new widgets can be composed out of
existing ones too. The process of composing widgets together is called composition.
The User Interface of the app is composed of many simplewidgets, each of them
handling one particular job. That is the reason why Flutter developers tend to think
of their flutter app as a tree of widgets.
• Unlike many other popular mobile platforms, Flutter doesn’t use JavaScript
in any way. Dart is the programming language. It compiles to binary code,
and that’s why it runs with the native performance of Objective-C, Swift, Java
or Kotlin.
Dart Overview
Dart is a client-optimized language for developing fast apps on any platform. Its goal
is to offer the most productive programming language for multi-platform
development, paired with a flexible execution runtime platform for app frameworks.
Dart also forms the foundation of Flutter. Dart provides the language and runtimes
that power Flutter apps, but Dart also supports many core developer tasks like
formatting, analyzing, and testing code.
The Dart language is type safe; it uses static type checking to ensure that a
variable’s value always matches the variable’s static type. Sometimes, this is
referred to as sound typing. The Dart typing system is also flexible, allowing the
use of a dynamic type combined with runtime checks, which can be useful during
experimentation or for code that needs to be especially dynamic.
Dart offers sound null safety, meaning that values can’t be null unless you say
they can be. With sound null safety, Dart can protect you from null exceptions at
runtime through static code analysis.
• Widgets
• Gestures
• Concept of State
• Layers
Widgets
Widgets are the primary component of any flutter application. It acts as a UI for
the user to interact with the application. Any flutter application is itself a widget
that is made up of a combination of widgets. In a standard application, the root
defines the structure of the application followed by a MaterialApp widget which
basically holds its internal components in place. This is where the properties of
the UI and the application itself is set. The MaterialApp has a Scaffold widget
thatconsists of the visible components (widgets) of the application. The Scaffold
has two primary properties namely the body and the appbar. It holds all the child
widgets and this is where all its properties are defined.
Inside Scaffold, there is usually an AppBar widget, which as the name suggests
defines the appbar of the application. The scaffold also has a body where all the
component widgets are placed. This is where these widget’s properties are set.
All these widgets combined form the Homepage of the application itself. The
Center widget has a property, Child, which refers to the actual content and it is
built using the Text widget.
Layers
All physical form of interaction with a flutter application is done through pre-
defined gestures. GestureDetectors are used for the same. It is an invisible
widget that is used to process physical interaction with the flutter application.
Theinteraction includes gestures like tapping, dragging, and swiping, etc. These
features can be used to creatively enhance the user experiences of the app by
making it perform desired actions based on simple gestures.
Concept of State
If you have ever worked with React js, you might be familiar with the concept of a
state. The states are nothing but data objects. Flutter also operates on similar turf.
For the management of state in a Flutter application, StatefulWidget is used. Similar
to the concept of state in React js, the re-rendering of widgets specific to the state
occurs whenever the state changes. This also avoids the re-rendering of the entire
application, every time the state of a widget changes.
Text()
Flutter cannot render text without knowing what’s the preference for text
direction.To render text, we have to set Text.textDirection.
Centre()
Center(…) is the widget that aligns another widget given in child property in the
center of itself. You’ll often see child and children properties in Flutter
applications, because almost all widgets are using them if they need one or
several widgets to be rendered inside of them.
A composition of widgets in Flutter is used to represent an interface, to change its
look, and to share data.
Container()
Scaffold
2.1 AIM:
To calculate Calculator using the features and using the data of a user.
2.2 SCOPE
The idea is to implement a calculator whilst learning the basics of Flutter. It should be
functional but not overly complicated to develop. For that reason, we delimit the feature
set by the following:
• It should have the possibility to let the user perform all basic calculations: add,
subtract, multiply, divide
• We do not work with float values, thus division only includes integers
• A clean button resets the state and enables the user to define a new calculation
• A bar at the top shows the current calculation with the first operand, the operator
and the second operand
• After a tap on the equals sign the user is presented the result of the calculation
2.3A FEASIBILITY STUDY
1. Technical Feasibility
2. Economic Feasibility
3. Environmental Feasibility
4. Feasibility in Operation
Technical Feasibility:
This research shows all of the technical details as well as the outcomes.
Becauseof the below-mentioned feature, the project "Calculator" is
theoretically viable. The project was created in Android Studio utilising the
Flutter Framework and Dart programming language, with a graphical user
interface.
Economic Feasibility:
The organisation must determine its overall financial status based on the
estimates acquired in the previous portions of the study. There are financial
benefits to the project as a result of better information reliability and accuracy.
Thesystem has little hardware requirements, which reduces the cost of
hardware acquisition.
Environmental Feasibility:
The method is simpler to use and does not necessitate any specific training.
Anyspecial events are alerted to the user through appropriate notifications
and messages. The user will have little trouble adapting to the system. The
system preserves exceptionally accurate records, and information may be
accessible in a matter of seconds.
2.4 EXISTING SYSTEM:
2.4.1 DISADVANTAGES:
Addition +
Subtraction -
Multiplication *
Division /
Percentage %
In this project as a backbone tool Dart is used to implement UI of the app and also
the logical part of the application. With the help software Android Studio, a
FlutterFramework is launched where Dart Language is used in backend.
The fastest developer tools for building market-leading apps and accelerating
performance. With an intelligent code editor, flexible build system, realtime
profilers and emulators. Building without limits. Code with confidence. Eliminate
tiresome tasks.
To Select Operators:
To Select the numbers is used:
To Select Option:
CHAPTER-3:
USED
In the Lib folder, there is a main.dart file already present. And now in the same
folder create a new file named buttons.dart. Starting with main.dart file.
Create MyApp class and make it StatelessWidget. Add an array of buttons to be
displayed. Set the background-color, text-color, functionality onTapped to the
buttons. Write a function to calculate the Answers
• Dart
import 'package:flutter/material.dart';
import 'buttons.dart';
import 'package:math_expressions/math_expressions.dart';
void main() {
runApp(MyApp());
}
// Array of button
final List<String> buttons = [
'C',
'+/-',
'%',
'DEL',
'7',
'8',
'9',
'/',
'4',
'5',
'6',
'x',
'1',
'2',
'3',
'-',
'0',
'.',
'=',
'+',
];
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: new AppBar(
title: new Text("Calculator"),
), //AppBar
backgroundColor: Colors.white38,
body: Column(
children: <Widget>[
Expanded(
child: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Container(
padding: EdgeInsets.all(20),
alignment: Alignment.centerRight,
child: Text(
userInput,
style: TextStyle(fontSize: 18, color: Colors.white),
),
),
Container(
padding: EdgeInsets.all(15),
alignment: Alignment.centerRight,
child: Text(
answer,
style: TextStyle(
fontSize: 30,
color: Colors.white,
fontWeight: FontWeight.bold),
),
)
]),
),
),
Expanded(
flex: 3,
child: Container(
child: GridView.builder(
itemCount: buttons.length,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 4),
itemBuilder: (BuildContext context, int index) {
// Clear Button
if (index == 0) {
return MyButton(
buttontapped: () {
setState(() {
userInput = '';
answer = '0';
});
},
buttonText: buttons[index],
color: Colors.blue[50],
textColor: Colors.black,
);
}
// +/- button
else if (index == 1) {
return MyButton(
buttonText: buttons[index],
color: Colors.blue[50],
textColor: Colors.black,
);
}
// % Button
else if (index == 2) {
return MyButton(
buttontapped: () {
setState(() {
userInput += buttons[index];
});
},
buttonText: buttons[index],
color: Colors.blue[50],
textColor: Colors.black,
);
}
// Delete Button
else if (index == 3) {
return MyButton(
buttontapped: () {
setState(() {
userInput =
userInput.substring(0, userInput.length - 1);
});
},
buttonText: buttons[index],
color: Colors.blue[50],
textColor: Colors.black,
);
}
// Equal_to Button
else if (index == 18) {
return MyButton(
buttontapped: () {
setState(() {
equalPressed();
});
},
buttonText: buttons[index],
color: Colors.orange[700],
textColor: Colors.white,
);
}
// other buttons
else {
return MyButton(
buttontapped: () {
setState(() {
userInput += buttons[index];
});
},
buttonText: buttons[index],
color: isOperator(buttons[index])
? Colors.blueAccent
: Colors.white,
textColor: isOperator(buttons[index])
? Colors.white
: Colors.black,
);
}
}), // GridView.builder
),
),
],
),
);
}
bool isOperator(String x) {
if (x == '/' || x == 'x' || x == '-' || x == '+' || x == '=') {
return true;
}
return false;
}
Parser p = Parser();
Expression exp = p.parse(finaluserinput);
ContextModel cm = ContextModel();
double eval = exp.evaluate(EvaluationType.REAL, cm);
answer = eval.toString();
}
}
In Flutter main.dart file is the entry point from which the code starts to executing. In
the main.dart file firstly material design package has been imported in addition
to math_expressions and buttons.dart file. Then a function runApp has been created
with parameter as MyApp. After the declaration of class MyApp which is a stateless
widget, the state of class MyApp has been laid out.
Step 3: Building the buttons.dart
In buttons.dart which is already imported in main.dart file we are declaring variables
that will be used throughout the program using a constructor. The color, text color,
button text, and the functionality of the button on tapped will be implemented
in main.dart file
• Dart
import 'package:flutter/material.dart';
// declaring variables
final color;
final textColor;
final String buttonText;
final buttontapped;
//Constructor
MyButton({this.color, this.textColor, this.buttonText, this.buttontapped});
@override
Widget build(BuildContext context) {
return GestureDetector(
onTap: buttontapped,
child: Padding(
padding: const EdgeInsets.all(0.2),
child: ClipRRect(
// borderRadius: BorderRadius.circular(25),
child: Container(
color: color,
child: Center(
child: Text(
buttonText,
style: TextStyle(
color: textColor,
fontSize: 25,
fontWeight: FontWeight.bold,
),
),
),
),
),
),
);
}
}
IMPLEMENTATION
1. ADDITION
2. SUBTRACTION
3. MULTIPLICATION
4. DIVISION
5. PERCENTAGE
Chapter 5:
import 'package:flutter/material.dart';
void main() {
runApp(myApp());
}
class myApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData(
primarySwatch: Colors.deepOrange,
),
home: HomePage(),
debugShowCheckedModeBanner: false,
);
}
}
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Calculator'),
),
body: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Expanded(
child: Container(
padding: EdgeInsets.all(10.0),
alignment: Alignment.bottomRight,
child: Text(
text,
style: TextStyle(
fontSize: 60.0,
fontWeight: FontWeight.w500,
color: Colors.deepOrange),
),
),
),
Row(
children: <Widget>[
customOutlineButton("9"),
customOutlineButton("8"),
customOutlineButton("7"),
customOutlineButton("+"),
],
),
Row(
children: <Widget>[
customOutlineButton("6"),
customOutlineButton("5"),
customOutlineButton("4"),
customOutlineButton("-"),
],
),
Row(
children: <Widget>[
customOutlineButton("3"),
customOutlineButton("2"),
customOutlineButton("1"),
customOutlineButton("x"),
],
),
Row(
children: <Widget>[
customOutlineButton("C"),
customOutlineButton("0"),
customOutlineButton("="),
customOutlineButton("/"),
],
),
],
),
),
);
}
Widget customOutlineButton(String val) {
return Expanded(
child: OutlineButton(
padding: EdgeInsets.all(25.0),
onPressed: () => btnClicked(val),
child: Text(
val,
style: TextStyle(fontSize: 35.0, color: Colors.deepOrange),
),
),
);
}
int first, second;
String res, text = "";
String opp;
void btnClicked(String btnText) {
if (btnText == "C") {
res = "";
text = "";
first = 0;
second = 0;
} else if (btnText == "+" ||
btnText == "-" ||
btnText == "x" ||
btnText == "/") {
first = int.parse(text);
res = "";
opp = btnText;
} else if (btnText == "=") {
second = int.parse(text);
if (opp == "+") {
res = (first + second).toString();
}
if (opp == "-") {
res = (first - second).toString();
}
if (opp == "x") {
res = (first * second).toString();
}
if (opp == "/") {
res = (first ~/ second).toString();
}
} else {
res = int.parse(text + btnText).toString();
}
setState(() {
text = res;
});
}
}