Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Java for Android
  • Android Studio
  • Android Kotlin
  • Kotlin
  • Flutter
  • Dart
  • Android Project
  • Android Interview
Open In App
Next Article:
Flutter - Create Animation Using the AnimatedAlign Widget
Next article icon

Creating a Calculator using Calculator Widget in Flutter

Last Updated : 26 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

If you need a Calculator in Flutter or need to do a small calculation in your flutter application, Writing your own code going to be tough, but Flutter gives you a SimpleCalculator Widget, Which allows you to create a Beautiful simple calculator. Only you need to set up the package in pubspec.yaml file and return the widget simpleCalculator.

A sample video given below gives an idea of what we are actually going to do.

https://media.geeksforgeeks.org/wp-content/uploads/20221016105213/fluttersimplecalculator-2022-10-16-10-50-39.mp4

Step By Step Implementation

Step 1: Create a New Project in Android Studio

To set up Flutter Development on Android Studio please refer to Android Studio Setup for Flutter Development, and then create a new project in Android Studio please refer to Creating a Simple Application in Flutter.

Step 2: Installation of Package

Install the package into the pubspec.yaml file that you will find in the root directory of the project.

flutter pub add flutter_simple_calculator

This will add a line like this to your package’s pubspec.yaml (and run an implicit flutter pub get):

 


Step 3: Import the Package

import 'package:flutter_simple_calculator/flutter_simple_calculator.dart';

Step 4: Create simpleCalculator Widget

Now all setups are done, Now we have to make a simpleCalculator Widget that is provided by the simple_calculator package. SimpleCalculator Widget allows us to set the parameters such as value, hideExpression, hideSurroundingBorder, autofocus, onChanged, theme.

Dart

double _currentValue;
SimpleCalculator(
    value: _currentValue!,
    hideExpression: false,
    hideSurroundingBorder: true,
    autofocus: true,
    onChanged: (key, value, expression) {
        setState(() {
            _currentValue = value ?? 0;
        });
    },
    theme: const CalculatorThemeData(
        borderColor: Colors.black,
        borderWidth: 2,
        displayColor: Colors.black54,
        displayStyle:
            TextStyle(fontSize: 80, color: Color.fromARGB(255, 18, 218, 24)),
            expressionColor: Colors.indigo,
            expressionStyle: TextStyle(fontSize: 20, color: Colors.white),
            operatorColor: Color.fromARGB(255, 130, 192, 85),
            operatorStyle: TextStyle(fontSize: 30, color: Colors.white),
            commandColor: Colors.orange,
            commandStyle: TextStyle(fontSize: 30, color: Colors.white),
            numColor: Colors.grey,
            numStyle: TextStyle(fontSize: 50, color: Colors.white),
    ),
);
                      
                       

Code Example:

Dart

import 'package:flutter/material.dart';
import 'package:flutter_simple_calculator/flutter_simple_calculator.dart';
  
void main() => runApp(const RunMyApp());
  
class RunMyApp extends StatelessWidget {
  const RunMyApp({Key? key}) : super(key: key);
  
  @override
  Widget build(BuildContext context) {
    return MaterialApp( // materialApp with debugbanner false
      debugShowCheckedModeBanner: false,
      theme: ThemeData(primarySwatch: Colors.green), // default theme
      home: Scaffold( // scaffold allows set appbar and it title
        appBar: AppBar(
          title: const Text('SimpleCalculator'),
        ),
        body: SizedBox(
          width: double.infinity, // width of the sizedbox.
          child: Calc(), // sizedbox taking class Calc 
        ),
      ),
    );
  }
}
  
class Calc extends StatefulWidget {
  const Calc({Key? key}) : super(key: key);
  
  @override
  _CalcState createState() => _CalcState();
}
  
class _CalcState extends State<Calc> {
  double? _currentValue = 0; // Variable that holds the any changes in the calc
  @override
  Widget build(BuildContext context) {
    var calc = SimpleCalculator( // SimpleCalculator widget to allow us to set it parameters
      value: _currentValue!, // value is to currentValue
      hideExpression: false,
      hideSurroundingBorder: true,
      autofocus: true,
      onChanged: (key, value, expression) {
        setState(() { // setState method call everytime when every changes occur 
          _currentValue = value ?? 0;
        });
      },
      theme: const CalculatorThemeData( // setting the theme of the calculator
        borderColor: Colors.black,
        borderWidth: 2,
        displayColor: Colors.black54,
        displayStyle:
            TextStyle(fontSize: 80, color: Color.fromARGB(255, 18, 218, 24)),
            expressionColor: Colors.indigo,
            expressionStyle: TextStyle(fontSize: 20, color: Colors.white),
            operatorColor: Color.fromARGB(255, 130, 192, 85),
            operatorStyle: TextStyle(fontSize: 30, color: Colors.white),
            commandColor: Colors.orange,
            commandStyle: TextStyle(fontSize: 30, color: Colors.white),
            numColor: Colors.grey,
            numStyle: TextStyle(fontSize: 50, color: Colors.white),
      ),
    );
    return SafeArea(child: calc); // showing the calculator
  }
}
                      
                       

Output:

https://media.geeksforgeeks.org/wp-content/uploads/20221016105213/fluttersimplecalculator-2022-10-16-10-50-39.mp4


Next Article
Flutter - Create Animation Using the AnimatedAlign Widget

M

ms471841
Improve
Article Tags :
  • Android
  • Dart
  • Flutter
  • Technical Scripter
  • Technical Scripter 2022

Similar Reads

  • Creating a Simple Application in Flutter
    Flutter is an open-source cross-platform mobile application development SDK created by Google. It is highly user-friendly and builds high-quality mobile applications. The intention behind this article is to guide readers through the process of building an application through Flutter by creating a si
    5 min read
  • Flutter - Create Animation Using the AnimatedAlign Widget
    The AnimatedAlign widget in Flutter is used to create animated transitions for aligning a child widget within a parent container. It smoothly animates the alignment property, allowing you to move a child widget from one position to another with a specified duration. In this article, we are going to
    4 min read
  • Simple Age Calculator App using Flutter
    Flutter SDK is an open-source software development kit for building beautiful UI which is natively compiled. In this article, we'll build a simple Flutter app that calculates a person's age based on their birthdate. To do this, we'll need to take input from the user, perform the calculations, and di
    3 min read
  • Advanced Calculator App using Flutter
    Flutter SDK is an open-source software development kit for building beautiful UI which is natively compiled. In this article, we are going to create an advanced calculator app by using some advanced packages available in Flutter. In this app, you get some functionality. In this app you have only one
    8 min read
  • Simple Calculator App using Flutter
    Flutter SDK is an open-source software development kit for building beautiful UI that is natively compiled. In this article, we will build a Simple Calculator App that can perform basic arithmetic operations like addition, subtraction, multiplication or division depending upon the user input. Making
    5 min read
  • Creating a Calculator for Android devices
    This post describes how to create a calculator application especially to help in competitive coding for android devices. The apk created can be used to install the application on different devices. The project has been designed for entry level android programmers. The Calculator Application The calc
    4 min read
  • FlatButton Widget in Flutter
    FlatButton is the material design widget in a flutter. It is a text label material widget that performs an action when the button is tapped. Let's understand with the help of examples. Disclaimer: As of May 2021 the FlatButton class in flutter is deprecated. TextButton class should be used instead.
    3 min read
  • Creating a Finance Tracker Application in Flutter
    Developing a new tracker for finance is a good practice to improve your skills and build a helpful application. Through Flutter, an open-source UI toolkit developed by Google, it is possible to design for iOS/ Android, web, and desktop. Here you will find out the recipe of how to create a finance tr
    6 min read
  • How to Create a Desktop Window Application in Flutter?
    The Flutter team recently released Flutter version 2.10 with Desktop support. Desktop support allows you to compile Flutter source code to a native Windows, macOS, or Linux desktop app. Flutter’s desktop support also extends to plugins—you can install existing plugins that support the Windows, macOS
    3 min read
  • How to Make Simple BMI Calculator App in Flutter?
    Flutter SDK is an open-source Software Development Kit for building beautiful UI natively compiled in Android Studio. In this article, we will create a Simple BMI Calculator App using Flutter in Android Studio that can take height and weight. Based on that, it will show you the BMI, as well as the t
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences