How to Create a Software Calculator Using Flutter ?
Yes we can make a Software Calculator in Flutter. because calculators are that can automatically carry out a sequence of operations under control of a stored program, much like a computer. A software calculator is a calculator that has been implemented as a computer program, rather than as a physical hardware device.we can go for configure our system for flutter.the reason behind of the making calculator in flutter is understanding of knowledge of layouts,widgets and logic development.
Requirements:
We have prepared a calculator in Flutter. Using Android Studio With Flutter SDK. Android Studio: 3.6.0 or Visual Studio
Android Virtual Device :Any Virtual Device ,
Android Version : Android 8.1 (Google Play),
Hint:Double Click on Emulator icon or select Start from Play Button.
Steps of Making of Calculator in Flutter.
Step 1: Start Android Studio Android Studio - Start A New Flutter Project.
Step 2: Select Flutter Application and Click on Next Button.
Step 3:Give project name in camelCase format.Then Select Flutter
SDK path.Then Click on Next Button.
Step4: Flutter gives by Default package name but we can change
the package name.Then click on Finish Button.
Step 5: open main.dart and remove by default code and copy this code and try to understand flutter syntax.
import 'package:flutter/material.dart';
void main(){
}
class MyApp extends StatelessWidget {
@override Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Ganesh(),
);
}
}
void main(){
}
class MyApp extends StatelessWidget {
@override Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Ganesh(),
);
}
}
runApp(MyApp());
class Ganesh extends StatefulWidget {
@override
_GaneshState createState() => _GaneshState();
}
class _GaneshState extends State<Ganesh> {
int firstnum;
int secondnum;
String texttodisplay="";
String res;
String operatortoperorm;
void btnclicked( String btnval){
if(btnval=="C"){
texttodisplay="";
firstnum=0;
secondnum=0;
res="";
}
else if(btnval=="+"||btnval=="-"||btnval=="x"||btnval=="/")
{
firstnum=int.parse(texttodisplay);
res="";
operatortoperorm=btnval;
}
else if (btnval=="="){
secondnum=int.parse(texttodisplay);
if(operatortoperorm=="+"){
res=(firstnum+secondnum).toString();
}
if(operatortoperorm=="-"){
res=(firstnum-secondnum).toString();
}
if(operatortoperorm=="x"){
res=(firstnum*secondnum).toString();
}
if(operatortoperorm=="/"){
res=(firstnum / secondnum).toString();
}
}
else{
res=int.parse(texttodisplay+btnval).toString();
}
setState(() {
texttodisplay=res;
});
}
Widget custombutton( String btnval){
return Expanded(child: OutlineButton(onPressed: ()=>btnclicked(btnval),
padding: EdgeInsets.all(25.0),
child: Text("$btnval",
style: TextStyle(fontSize: 25.0),),
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Ganesh's Calculator"),
backgroundColor: Colors.purple,
),
body: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Expanded(child: Container(
padding: EdgeInsets.all(10.0),
alignment: Alignment.bottomRight,
child: Text("$texttodisplay",style: TextStyle(
fontSize: 30.0,
fontWeight:FontWeight.w600,
),
),
),
),
Row(
children: <Widget>[
custombutton("9"),
custombutton("8"),
custombutton("7"),
custombutton("+"),
],
),Row(
children: <Widget>[
custombutton("6"),
custombutton("5"),
custombutton("4"),
custombutton("-"),
],
),
Row(
children: <Widget>[
custombutton("3"),
custombutton("2"),
custombutton("1"),
custombutton("x"),
],
),Row(
children: <Widget>[
custombutton("C"),
custombutton("0"),
custombutton("="),
custombutton("/"),
],
),
],),
),
);
}
}
Screenshot of Coding first 70 lines.
Screenshot of Coding first 70 lines.
Step 6: Run the Project.
Step 7: Output of the Coding.
Very Helpful,Thank you
ReplyDeleteWelcome🙌
Deletegood job
ReplyDeleteWelcome
DeleteLooking for the best Mobile app development company? I suggest you go for AppClues Infotech – A foremost Mobile app development company based in the USA . They help you with the overall application development solutions for your company.
ReplyDeleteiOS App Development Company
Android App Development Company
Cross-Platform App Development Company
Enterprise App Development Company
MCommerce Mobile App Development Company
Wallet App Development Company