<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Anand C</title>
    <description>The latest articles on Forem by Anand C (@anand_27).</description>
    <link>https://forem.com/anand_27</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1107257%2F22fdfc7d-a0b0-4a41-a492-ed4db9186ba8.jpeg</url>
      <title>Forem: Anand C</title>
      <link>https://forem.com/anand_27</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/anand_27"/>
    <language>en</language>
    <item>
      <title>🧮 Build Your Own `wc` Tool in Java — A Minimal Clone of the Unix Word Count Utility</title>
      <dc:creator>Anand C</dc:creator>
      <pubDate>Sat, 31 May 2025 18:32:03 +0000</pubDate>
      <link>https://forem.com/anand_27/build-your-own-wc-tool-in-java-a-minimal-clone-of-the-unix-word-count-utility-1adb</link>
      <guid>https://forem.com/anand_27/build-your-own-wc-tool-in-java-a-minimal-clone-of-the-unix-word-count-utility-1adb</guid>
      <description>&lt;p&gt;If you've ever used a Linux terminal, you're probably familiar with the &lt;code&gt;wc&lt;/code&gt; command — a simple yet powerful utility that prints the number of lines, words, and bytes (or characters) in a file or input stream. As part of my learning journey in Java and systems programming, I decided to implement a basic clone of the &lt;code&gt;wc&lt;/code&gt; tool in Java.&lt;/p&gt;

&lt;p&gt;In this blog post, I'll walk you through what I've built, what works, what doesn't (yet), and share the code for anyone looking to experiment or contribute.&lt;/p&gt;




&lt;h2&gt;
  
  
  🚀 Project Overview
&lt;/h2&gt;

&lt;p&gt;🔗 &lt;strong&gt;GitHub Repository&lt;/strong&gt;: &lt;a href="https://github.com/anandshaji679322/WC-Tool" rel="noopener noreferrer"&gt;github.com/anandshaji679322/WC-Tool&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  ✅ Features Implemented
&lt;/h3&gt;

&lt;p&gt;This tool supports the following options, just like the original &lt;code&gt;wc&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;-c&lt;/code&gt;: Count bytes&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-m&lt;/code&gt;: Count characters&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-w&lt;/code&gt;: Count words&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-l&lt;/code&gt;: Count lines&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It works both with file input and standard input (&lt;code&gt;stdin&lt;/code&gt;) for most flags.&lt;/p&gt;

&lt;h3&gt;
  
  
  🛠️ Technologies Used
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Java&lt;/li&gt;
&lt;li&gt;Basic I/O: &lt;code&gt;FileInputStream&lt;/code&gt;, &lt;code&gt;FileReader&lt;/code&gt;, &lt;code&gt;Scanner&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Stream handling with &lt;code&gt;System.in&lt;/code&gt; and custom logic&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  📦 How to Use
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Count bytes in a file:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;java ccwc &lt;span class="nt"&gt;-c&lt;/span&gt; test.txt

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Count words from stdin:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cat test.txt | java ccwc -w

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Count lines from stdin:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cat test.txt | java ccwc -l
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Count characters from stdin:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cat test.txt | java ccwc -m  # ❌ Not yet fully working
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  ⚠️ Known Issues
&lt;/h2&gt;

&lt;p&gt;🧪 Currently, the &lt;code&gt;-c&lt;/code&gt; (byte count) and &lt;code&gt;-m&lt;/code&gt; (character count) flags &lt;strong&gt;do not work correctly&lt;/strong&gt; when used with stdin (&lt;code&gt;cat file | java ccwc -c&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;I attempted different approaches to fix this issue, including using &lt;code&gt;BufferedOutputStream&lt;/code&gt; and &lt;code&gt;InputStreamReader&lt;/code&gt; to handle the input stream, but both methods did not resolve the problem.&lt;/p&gt;




&lt;h2&gt;
  
  
  🔍 Code Highlights
&lt;/h2&gt;

&lt;p&gt;Here’s an example of how I count words from a file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;wordCountFile&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;fileName&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="kd"&gt;throws&lt;/span&gt; &lt;span class="nc"&gt;FileNotFoundException&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Scanner&lt;/span&gt; &lt;span class="n"&gt;sc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Scanner&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;File&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;fileName&lt;/span&gt;&lt;span class="o"&gt;)))&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sc&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;hasNext&lt;/span&gt;&lt;span class="o"&gt;())&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="o"&gt;++;&lt;/span&gt;
            &lt;span class="n"&gt;sc&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;next&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  📚 What I Learned
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Handling standard input (&lt;code&gt;System.in&lt;/code&gt;) in Java requires careful stream management.&lt;/li&gt;
&lt;li&gt;When designing CLI tools, it’s important to handle edge cases like invalid flags and argument lengths.&lt;/li&gt;
&lt;li&gt;Java's &lt;code&gt;Scanner&lt;/code&gt; is a simple but effective class for parsing input.&lt;/li&gt;
&lt;li&gt;Working with byte vs character streams teaches you a lot about encoding.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  📈 What’s Next
&lt;/h2&gt;

&lt;p&gt;If I revisit this project, I want to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;✅ Fix the stdin issue for &lt;code&gt;-c&lt;/code&gt; and &lt;code&gt;-m&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;➕ Add support for multiple flags at once (like &lt;code&gt;wc -cwm file.txt&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;📦 Package it as a standalone &lt;code&gt;.jar&lt;/code&gt; with command-line installation instructions&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  👨‍💻 Conclusion
&lt;/h3&gt;

&lt;p&gt;This was a great mini-project that helped me get hands-on with Java’s I/O system while building a tool similar to a real-world Unix utility.&lt;br&gt;&lt;br&gt;
If you're learning Java or preparing for systems programming interviews, I highly recommend trying something similar!&lt;/p&gt;

&lt;p&gt;Feel free to fork the project or contribute on GitHub:&lt;br&gt;&lt;br&gt;
🔗 &lt;a href="https://github.com/anandshaji679322/WC-Tool" rel="noopener noreferrer"&gt;github.com/anandshaji679322/WC-Tool&lt;/a&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>linux</category>
    </item>
    <item>
      <title>Creating a Simple Calculator UI with Flutter: Inspired Design from Dribbble</title>
      <dc:creator>Anand C</dc:creator>
      <pubDate>Thu, 29 Jun 2023 12:27:08 +0000</pubDate>
      <link>https://forem.com/anand_27/creating-a-simple-calculator-ui-with-flutter-inspired-design-from-dribbble-34af</link>
      <guid>https://forem.com/anand_27/creating-a-simple-calculator-ui-with-flutter-inspired-design-from-dribbble-34af</guid>
      <description>&lt;p&gt;Welcome to this tutorial where we'll be enhancing the UI of a simple calculator app using Flutter, drawing inspiration from a beautiful design on Dribbble. In this tutorial, we'll explore how to transform the appearance of the calculator app by implementing a captivating and user-friendly user interface.&lt;/p&gt;

&lt;p&gt;Calculators are a common tool, and by improving the UI of our calculator app, we can create a visually appealing and engaging user experience. We'll walk through the step-by-step process of refining the design elements, making it more intuitive and aesthetically pleasing.&lt;/p&gt;

&lt;p&gt;To begin, we'll set up our Flutter project and ensure we have the necessary dependencies installed. With the foundation in place, we'll dive into modifying the existing UI to align with the design from Dribbble. By leveraging Flutter's powerful widget system, we'll customize buttons, layouts, and colors to give the calculator a fresh and captivating look.&lt;/p&gt;

&lt;p&gt;Throughout the tutorial, we'll focus solely on the UI enhancements, making adjustments to the visual elements and overall styling. We'll pay attention to details such as typography, color schemes, spacing, and alignment to create a visually coherent and delightful UI.&lt;/p&gt;

&lt;p&gt;By the end of this tutorial, you'll have a transformed calculator app with an upgraded user interface, making it more visually appealing and user-friendly. You'll gain valuable experience in modifying Flutter UI components and exploring design concepts to enhance the overall look and feel of your applications.&lt;/p&gt;

&lt;p&gt;So, let's embark on this journey to elevate the UI of our calculator app using Flutter, drawing inspiration from a stunning design on Dribbble!&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Setting Up the Flutter App's Root Structure&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Flutter Demo',

      home: MyHomePage(),
    );
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;main()&lt;/code&gt; function serves as the entry point of the Flutter app. It runs the app by calling &lt;code&gt;runApp()&lt;/code&gt; and passing in an instance of the &lt;code&gt;MyApp&lt;/code&gt; class.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;MyApp&lt;/code&gt; class is a &lt;code&gt;StatelessWidget&lt;/code&gt; that represents the root of the application. It overrides the &lt;code&gt;build&lt;/code&gt; method to return a &lt;code&gt;MaterialApp&lt;/code&gt; widget, which configures the app's settings and theme.&lt;/p&gt;

&lt;p&gt;Within the &lt;code&gt;MaterialApp&lt;/code&gt;, the &lt;code&gt;debugShowCheckedModeBanner&lt;/code&gt; property is set to &lt;code&gt;false&lt;/code&gt; to hide the debug banner, and the &lt;code&gt;title&lt;/code&gt; property is set to "Flutter Demo".&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;home&lt;/code&gt; property of &lt;code&gt;MaterialApp&lt;/code&gt; is set to an instance of &lt;code&gt;MyHomePage&lt;/code&gt;, which will be the initial screen of your app.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;MyHomePage&lt;/code&gt; class, which is not provided in the code snippet, should be defined as a &lt;code&gt;StatelessWidget&lt;/code&gt; or &lt;code&gt;StatefulWidget&lt;/code&gt; and represent the main screen of your app. It should be responsible for rendering the UI and handling user interactions.&lt;/p&gt;

&lt;p&gt;Overall, the code sets up the basic structure of the app and configures the root of the application with the &lt;code&gt;MaterialApp&lt;/code&gt;. You can proceed to implement the &lt;code&gt;MyHomePage&lt;/code&gt; class to build and customize the UI and functionality of your app.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Basic Home Screen Structure&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import 'package:flutter/material.dart';

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  State&amp;lt;MyHomePage&amp;gt; createState() =&amp;gt; _MyHomePageState();
}

class _MyHomePageState extends State&amp;lt;MyHomePage&amp;gt; {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Container(
          color: Color(0xff22252D),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: [
              Container(
                height: 240.0,
                color: Color(0xff22252D),
                padding: EdgeInsets.only(top: 150.0),
              ),
              Expanded(
                child: Container(
                  decoration: BoxDecoration(
                    color: Color(0xff292D36),
                  ),

                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The provided code represents the &lt;code&gt;MyHomePage&lt;/code&gt; class, which serves as the main screen of your calculator app.&lt;/p&gt;

&lt;p&gt;Inside the &lt;code&gt;build&lt;/code&gt; method, a &lt;code&gt;Scaffold&lt;/code&gt; widget is returned, providing the basic structure for the app layout. The &lt;code&gt;Scaffold&lt;/code&gt; contains a &lt;code&gt;SafeArea&lt;/code&gt; widget to ensure the content is displayed within the safe area of the device screen.&lt;/p&gt;

&lt;p&gt;The main content is wrapped inside a &lt;code&gt;Container&lt;/code&gt; widget, which has a background color of &lt;code&gt;Color(0xff22252D)&lt;/code&gt;. This container represents the main body of the screen and is divided into two sections.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Display Section:

&lt;ul&gt;
&lt;li&gt;This section is represented by a &lt;code&gt;Container&lt;/code&gt; with a height of 240.0 and the same background color as the main container.&lt;/li&gt;
&lt;li&gt;Currently, there is no content inside this container, as the code only sets its height and background color.&lt;/li&gt;
&lt;li&gt;This section is represented by an &lt;code&gt;Expanded&lt;/code&gt; widget, which takes up the remaining available space in the container.&lt;/li&gt;
&lt;li&gt;Inside the &lt;code&gt;Expanded&lt;/code&gt; widget, there is a &lt;code&gt;Container&lt;/code&gt; that serves as the background for the button section, with a color of &lt;code&gt;Color(0xff292D36)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Currently, there is no content inside this container, as the code only sets its color.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Overall, the code provides the basic structure for the main screen of your calculator app. As shown below👇&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff9pjhk6jzpw9fu6peb4h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ff9pjhk6jzpw9fu6peb4h.png" alt="Basic Home Screen"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Basic Calculator UI Implementation&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import 'package:flutter/material.dart';

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  State&amp;lt;MyHomePage&amp;gt; createState() =&amp;gt; _MyHomePageState();
}

class _MyHomePageState extends State&amp;lt;MyHomePage&amp;gt; {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Container(
          color: Color(0xff22252D),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: [
              Container(
                height: 240.0,
                color: Color(0xff22252D),
                padding: EdgeInsets.only(top: 150.0),
//New changes happen below 👇
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.end,
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: [
                    Text(
                      textAlign: TextAlign.right,
                      style: TextStyle(
                        // fontWeight: FontWeight.bold,
                        fontSize: 25.0,
                        color: Colors.white,
                      ),
                      "302 x 75",
                    ),
                    Text(
                      textAlign: TextAlign.right,
                      style: TextStyle(
                        fontWeight: FontWeight.bold,
                        fontSize: 45.0,
                        color: Colors.white,
                      ),
                      "22650",
                    ),
                  ],
                ),

              ),
              Expanded(
                child: Container(
                  decoration: BoxDecoration(
                    color: Color(0xff292D36),
                  ),

                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Inside the first &lt;code&gt;Container&lt;/code&gt;, a &lt;code&gt;Column&lt;/code&gt; widget is added. This allows for the vertical arrangement of multiple child widgets.&lt;/li&gt;
&lt;li&gt;Within the &lt;code&gt;Column&lt;/code&gt; widget, two &lt;code&gt;Text&lt;/code&gt; widgets are added. These are used to display text elements on the screen.&lt;/li&gt;
&lt;li&gt;The first &lt;code&gt;Text&lt;/code&gt; widget is aligned to the right (&lt;code&gt;textAlign: TextAlign.right&lt;/code&gt;) and styled with a font size of 25.0 and white color.&lt;/li&gt;
&lt;li&gt;The text content of the first &lt;code&gt;Text&lt;/code&gt; widget is set to "302 x 75", which is dummy data used for setting up the UI.&lt;/li&gt;
&lt;li&gt;The second &lt;code&gt;Text&lt;/code&gt; widget is also aligned to the right and styled with a font size of 45.0, white color, and a bold font weight.&lt;/li&gt;
&lt;li&gt;The text content of the second &lt;code&gt;Text&lt;/code&gt; widget is set to "22650", which is also dummy data used for setting up the UI..&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These changes enhance the appearance of the home screen by adding a visually appealing section with two text elements that display dummy data, specifically "302 x 75" and "22650". Please note that these values are placeholders and can be replaced with actual data in your calculator app in further steps.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frnocgijftd2aerwarl9o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frnocgijftd2aerwarl9o.png" alt="calculator UI"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;First row of button&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  State&amp;lt;MyHomePage&amp;gt; createState() =&amp;gt; _MyHomePageState();
}

class _MyHomePageState extends State&amp;lt;MyHomePage&amp;gt; {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Container(
          color: Color(0xff22252D),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: [
              Container(
                height: 240.0,
                color: Color(0xff22252D),
                padding: EdgeInsets.only(top: 150.0),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.end,
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: [
                    Text(
                      textAlign: TextAlign.right,
                      style: TextStyle(
                        // fontWeight: FontWeight.bold,
                        fontSize: 25.0,
                        color: Colors.white,
                      ),
                      "302 x 75",
                    ),
                    Text(
                      textAlign: TextAlign.right,
                      style: TextStyle(
                        fontWeight: FontWeight.bold,
                        fontSize: 45.0,
                        color: Colors.white,
                      ),
                      "22650",
                    ),
                  ],
                ),
              ),
              Expanded(
                child: Container(
                  decoration: BoxDecoration(
                    color: Color(0xff292D36),
                  ),
                  child: Column(
                    children: [
//New changes happen below 👇
                      Row(
                        children: [
                          Padding(
                            padding: EdgeInsets.only(left: 20.0, top: 20.0),
                            child: TextButton(
                              onPressed: () {
                                print("ac");
                              },
                              style: ButtonStyle(
                                  fixedSize: MaterialStateProperty.all(
                                      Size(75.0, 70.0)),
                                  backgroundColor: MaterialStateProperty.all(
                                      Color(0xff272B34))),
                              child: Text(
                                "AC",
                                style: TextStyle(
                                  fontSize: 25.0,
                                  color: MaterialStateColor.resolveWith(
                                    (states) =&amp;gt; Color(0xff26E8C6),
                                  ),
                                ),
                              ),
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.only(left: 20.0, top: 20.0),
                            child: TextButton(
                              onPressed: () {
                                print("+/-");
                              },
                              style: ButtonStyle(
                                  fixedSize: MaterialStateProperty.all(
                                      Size(75.0, 70.0)),
                                  backgroundColor: MaterialStateProperty.all(
                                      Color(0xff272B34))),
                              child: Text(
                                "+/-",
                                style: TextStyle(
                                  fontSize: 25.0,
                                  color: MaterialStateColor.resolveWith(
                                    (states) =&amp;gt; Color(0xff26E8C6),
                                  ),
                                ),
                              ),
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.only(left: 20.0, top: 20.0),
                            child: TextButton(
                              onPressed: () {
                                print("ac");
                              },
                              style: ButtonStyle(
                                  fixedSize: MaterialStateProperty.all(
                                      Size(75.0, 70.0)),
                                  backgroundColor: MaterialStateProperty.all(
                                      Color(0xff272B34))),
                              child: Icon(
                                CupertinoIcons.divide,
                                color: MaterialStateColor.resolveWith(
                                    (states) =&amp;gt; Color(0xff26E8C6)),
                              ),
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.only(left: 20.0, top: 20.0),
                            child: TextButton(
                              onPressed: () {
                                print("ac");
                              },
                              style: ButtonStyle(
                                  fixedSize: MaterialStateProperty.all(
                                      Size(75.0, 70.0)),
                                  backgroundColor: MaterialStateProperty.all(
                                      Color(0xff272B34))),
                              child: Text("AC"),
                            ),
                          ),
                        ],
                      )
                    ],
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The updated code focuses on improving the calculator interface by introducing a button UI and utilizing the TextButton widget for interactive functionality. The code includes the implementation of various buttons that are essential for performing calculator operations.&lt;/p&gt;

&lt;p&gt;The buttons are arranged in a Row widget, enabling them to be displayed horizontally, creating a compact and visually appealing layout. Each button is styled with specific attributes such as size, background color, and text/icon color to ensure consistency and aesthetic appeal.&lt;/p&gt;

&lt;p&gt;To accommodate the buttons and other elements of the calculator interface, a Column widget is introduced within an Expanded container. This arrangement allows for proper spacing and layout management, ensuring a visually coherent and organized interface.&lt;/p&gt;

&lt;p&gt;The newly added buttons provide essential functionality to the calculator. For instance, the "AC" button, when pressed, clears the input and resets the calculator, providing a convenient way to start fresh. The "+/-" button allows users to change the sign of the displayed number, facilitating calculations involving positive and negative values.&lt;/p&gt;

&lt;p&gt;Additionally, a "mod" button is included, represented by the "%" symbol. This button performs the modulus operation, calculating the remainder of a division operation. It offers an essential feature for users working with modular arithmetic.&lt;/p&gt;

&lt;p&gt;The TextButton widget is used to create these buttons, providing a responsive and interactive user experience. Each button is styled with attention to detail, ensuring visual coherence and intuitive design. The size, background color, and text/icon color are carefully selected to match the overall aesthetics of the calculator interface.&lt;/p&gt;

&lt;p&gt;By incorporating these changes, the calculator UI becomes more interactive and user-friendly. Users can now perform calculations and operations efficiently by utilizing the provided buttons. The enhanced button functionality enhances the overall usability and user experience of the calculator app.&lt;/p&gt;

&lt;p&gt;This comprehensive update brings a more engaging and functional calculator interface, making it easier for users to perform calculations and interact with the app effectively.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;A Sleek and Intuitive Interface for a Basic Calculator&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  State&amp;lt;MyHomePage&amp;gt; createState() =&amp;gt; _MyHomePageState();
}

class _MyHomePageState extends State&amp;lt;MyHomePage&amp;gt; {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Container(
          color: Color(0xff22252D),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: [
              Container(
                height: 240.0,
                color: Color(0xff22252D),
                padding: EdgeInsets.only(top: 150.0),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.end,
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: [
                    Text(
                      textAlign: TextAlign.right,
                      style: TextStyle(
                        // fontWeight: FontWeight.bold,
                        fontSize: 25.0,
                        color: Colors.white,
                      ),
                      "302 x 75",
                    ),
                    Text(
                      textAlign: TextAlign.right,
                      style: TextStyle(
                        fontWeight: FontWeight.bold,
                        fontSize: 45.0,
                        color: Colors.white,
                      ),
                      "22650",
                    ),
                  ],
                ),
              ),
              Expanded(
                child: Container(
                  decoration: BoxDecoration(
                    color: Color(0xff292D36),
                  ),
                  child: Column(
                    children: [
                      Row(
                        children: [
                          Padding(
                            padding: EdgeInsets.only(left: 20.0, top: 10.0),
                            child: TextButton(
                              onPressed: () {
                                print("ac");
                              },
                              style: ButtonStyle(
                                  fixedSize: MaterialStateProperty.all(
                                      Size(75.0, 70.0)),
                                  backgroundColor: MaterialStateProperty.all(
                                      Color(0xff272B34))),
                              child: Text(
                                "AC",
                                style: TextStyle(
                                  fontSize: 25.0,
                                  color: MaterialStateColor.resolveWith(
                                    (states) =&amp;gt; Color(0xff26E8C6),
                                  ),
                                ),
                              ),
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.only(left: 20.0, top: 10.0),
                            child: TextButton(
                              onPressed: () {
                                print("+/-");
                              },
                              style: ButtonStyle(
                                  fixedSize: MaterialStateProperty.all(
                                      Size(75.0, 70.0)),
                                  backgroundColor: MaterialStateProperty.all(
                                      Color(0xff272B34))),
                              child: Icon(
                                CupertinoIcons.minus_slash_plus,
                                size: 30.0,
                                color: MaterialStateColor.resolveWith(
                                        (states) =&amp;gt; Color(0xff26E8C6)),
                              ),
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.only(left: 20.0, top: 10.0),
                            child: TextButton(
                              onPressed: () {
                                print("%");
                              },
                              style: ButtonStyle(
                                  fixedSize: MaterialStateProperty.all(
                                      Size(75.0, 70.0)),
                                  backgroundColor: MaterialStateProperty.all(
                                      Color(0xff272B34))),
                              child: Text(
                                "%",
                                style: TextStyle(
                                  fontSize: 25.0,
                                  color: MaterialStateColor.resolveWith(
                                        (states) =&amp;gt; Color(0xff26E8C6),
                                  ),
                                ),
                              ),
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.only(left: 20.0, top: 10.0),
                            child: TextButton(
                              onPressed: () {
                                print("/");
                              },
                              style: ButtonStyle(
                                  fixedSize: MaterialStateProperty.all(
                                      Size(75.0, 70.0)),
                                  backgroundColor: MaterialStateProperty.all(
                                      Color(0xff272B34))),
                              child: Icon(
                                CupertinoIcons.divide,
                                size: 30.0,
                                color: MaterialStateColor.resolveWith(
                                        (states) =&amp;gt; Color(0xffE78388)),
                              ),
                            ),
                          ),
                        ],
                      ),
//New Changes happen below👇
                      Row(
                        children: [
                          Padding(
                            padding: EdgeInsets.only(left: 20.0, top: 10.0),
                            child: TextButton(
                              onPressed: () {
                                print("7");
                              },
                              style: ButtonStyle(
                                  fixedSize: MaterialStateProperty.all(
                                      Size(75.0, 70.0)),
                                  backgroundColor: MaterialStateProperty.all(
                                      Color(0xff272B34))),
                              child: Text(
                                "7",
                                style: TextStyle(
                                  fontSize: 25.0,
                                  color: MaterialStateColor.resolveWith(
                                        (states) =&amp;gt; Colors.white,
                                  ),
                                ),
                              ),
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.only(left: 20.0, top: 10.0),
                            child: TextButton(
                              onPressed: () {
                                print("8");
                              },
                              style: ButtonStyle(
                                  fixedSize: MaterialStateProperty.all(
                                      Size(75.0, 70.0)),
                                  backgroundColor: MaterialStateProperty.all(
                                      Color(0xff272B34))),
                              child: Text(
                                "8",
                                style: TextStyle(
                                  fontSize: 25.0,
                                  color: MaterialStateColor.resolveWith(
                                        (states) =&amp;gt; Colors.white,
                                  ),
                                ),
                              ),
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.only(left: 20.0, top: 10.0),
                            child: TextButton(
                              onPressed: () {
                                print("9");
                              },
                              style: ButtonStyle(
                                  fixedSize: MaterialStateProperty.all(
                                      Size(75.0, 70.0)),
                                  backgroundColor: MaterialStateProperty.all(
                                      Color(0xff272B34))),
                              child: Text(
                                "9",
                                style: TextStyle(
                                  fontSize: 25.0,
                                  color: MaterialStateColor.resolveWith(
                                        (states) =&amp;gt; Colors.white,
                                  ),
                                ),
                              ),
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.only(left: 20.0, top: 10.0),
                            child: TextButton(
                              onPressed: () {
                                print("x");
                              },
                              style: ButtonStyle(
                                  fixedSize: MaterialStateProperty.all(
                                      Size(75.0, 70.0)),
                                  backgroundColor: MaterialStateProperty.all(
                                      Color(0xff272B34))),
                              child: Icon(
                                CupertinoIcons.multiply,
                                size: 30.0,
                                color: MaterialStateColor.resolveWith(
                                        (states) =&amp;gt; Color(0xffE78388)),
                              ),
                            ),
                          ),
                        ],
                      ),
                      Row(
                        children: [
                          Padding(
                            padding: EdgeInsets.only(left: 20.0, top: 10.0),
                            child: TextButton(
                              onPressed: () {
                                print("4");
                              },
                              style: ButtonStyle(
                                  fixedSize: MaterialStateProperty.all(
                                      Size(75.0, 70.0)),
                                  backgroundColor: MaterialStateProperty.all(
                                      Color(0xff272B34))),
                              child: Text(
                                "4",
                                style: TextStyle(
                                  fontSize: 25.0,
                                  color: MaterialStateColor.resolveWith(
                                        (states) =&amp;gt; Colors.white,
                                  ),
                                ),
                              ),
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.only(left: 20.0, top: 10.0),
                            child: TextButton(
                              onPressed: () {
                                print("5");
                              },
                              style: ButtonStyle(
                                  fixedSize: MaterialStateProperty.all(
                                      Size(75.0, 70.0)),
                                  backgroundColor: MaterialStateProperty.all(
                                      Color(0xff272B34))),
                              child: Text(
                                "5",
                                style: TextStyle(
                                  fontSize: 25.0,
                                  color: MaterialStateColor.resolveWith(
                                        (states) =&amp;gt; Colors.white,
                                  ),
                                ),
                              ),
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.only(left: 20.0, top: 10.0),
                            child: TextButton(
                              onPressed: () {
                                print("6");
                              },
                              style: ButtonStyle(
                                  fixedSize: MaterialStateProperty.all(
                                      Size(75.0, 70.0)),
                                  backgroundColor: MaterialStateProperty.all(
                                      Color(0xff272B34))),
                              child: Text(
                                "6",
                                style: TextStyle(
                                  fontSize: 25.0,
                                  color: MaterialStateColor.resolveWith(
                                        (states) =&amp;gt; Colors.white,
                                  ),
                                ),
                              ),
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.only(left: 20.0, top: 10.0),
                            child: TextButton(
                              onPressed: () {
                                print("-");
                              },
                              style: ButtonStyle(
                                  fixedSize: MaterialStateProperty.all(
                                      Size(75.0, 70.0)),
                                  backgroundColor: MaterialStateProperty.all(
                                      Color(0xff272B34))),
                              child: Icon(
                                CupertinoIcons.minus,
                                size: 30.0,
                                color: MaterialStateColor.resolveWith(
                                        (states) =&amp;gt; Color(0xffE78388)),
                              ),
                            ),
                          ),
                        ],
                      ),
                      Row(
                        children: [
                          Padding(
                            padding: EdgeInsets.only(left: 20.0, top: 10.0),
                            child: TextButton(
                              onPressed: () {
                                print("1");
                              },
                              style: ButtonStyle(
                                  fixedSize: MaterialStateProperty.all(
                                      Size(75.0, 70.0)),
                                  backgroundColor: MaterialStateProperty.all(
                                      Color(0xff272B34))),
                              child: Text(
                                "1",
                                style: TextStyle(
                                  fontSize: 25.0,
                                  color: MaterialStateColor.resolveWith(
                                        (states) =&amp;gt; Colors.white,
                                  ),
                                ),
                              ),
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.only(left: 20.0, top: 10.0),
                            child: TextButton(
                              onPressed: () {
                                print("2");
                              },
                              style: ButtonStyle(
                                  fixedSize: MaterialStateProperty.all(
                                      Size(75.0, 70.0)),
                                  backgroundColor: MaterialStateProperty.all(
                                      Color(0xff272B34))),
                              child: Text(
                                "2",
                                style: TextStyle(
                                  fontSize: 25.0,
                                  color: MaterialStateColor.resolveWith(
                                        (states) =&amp;gt; Colors.white,
                                  ),
                                ),
                              ),
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.only(left: 20.0, top: 10.0),
                            child: TextButton(
                              onPressed: () {
                                print("3");
                              },
                              style: ButtonStyle(
                                  fixedSize: MaterialStateProperty.all(
                                      Size(75.0, 70.0)),
                                  backgroundColor: MaterialStateProperty.all(
                                      Color(0xff272B34))),
                              child: Text(
                                "3",
                                style: TextStyle(
                                  fontSize: 25.0,
                                  color: MaterialStateColor.resolveWith(
                                        (states) =&amp;gt; Colors.white,
                                  ),
                                ),
                              ),
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.only(left: 20.0, top: 10.0),
                            child: TextButton(
                              onPressed: () {
                                print("+");
                              },
                              style: ButtonStyle(
                                  fixedSize: MaterialStateProperty.all(
                                      Size(75.0, 70.0)),
                                  backgroundColor: MaterialStateProperty.all(
                                      Color(0xff272B34))),
                              child: Icon(
                                CupertinoIcons.plus,
                                size: 30.0,
                                color: MaterialStateColor.resolveWith(
                                        (states) =&amp;gt; Color(0xffE78388)),
                              ),
                            ),
                          ),
                        ],
                      ),
                      Row(
                        children: [
                          Padding(
                            padding: EdgeInsets.only(left: 20.0, top: 10.0),
                            child: TextButton(
                              onPressed: () {
                                print("reset");
                              },
                              style: ButtonStyle(
                                  fixedSize: MaterialStateProperty.all(
                                      Size(75.0, 70.0)),
                                  backgroundColor: MaterialStateProperty.all(
                                      Color(0xff272B34))),
                              child: Icon(
                                CupertinoIcons.restart,
                                size: 30.0,
                                color: MaterialStateColor.resolveWith(
                                        (states) =&amp;gt; Colors.white),
                              ),
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.only(left: 20.0, top: 10.0),
                            child: TextButton(
                              onPressed: () {
                                print("0");
                              },
                              style: ButtonStyle(
                                  fixedSize: MaterialStateProperty.all(
                                      Size(75.0, 70.0)),
                                  backgroundColor: MaterialStateProperty.all(
                                      Color(0xff272B34))),
                              child: Text(
                                "0",
                                style: TextStyle(
                                  fontSize: 25.0,
                                  color: MaterialStateColor.resolveWith(
                                        (states) =&amp;gt; Colors.white,
                                  ),
                                ),
                              ),
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.only(left: 20.0, top: 10.0),
                            child: TextButton(
                              onPressed: () {
                                print(".");
                              },
                              style: ButtonStyle(
                                  fixedSize: MaterialStateProperty.all(
                                      Size(75.0, 70.0)),
                                  backgroundColor: MaterialStateProperty.all(
                                      Color(0xff272B34))),
                              child: Text(
                                ".",
                                style: TextStyle(
                                  fontSize: 25.0,
                                  color: MaterialStateColor.resolveWith(
                                        (states) =&amp;gt; Colors.white,
                                  ),
                                ),
                              ),
                            ),
                          ),
                          Padding(
                            padding: EdgeInsets.only(left: 20.0, top: 10.0),
                            child: TextButton(
                              onPressed: () {
                                print("=");
                              },
                              style: ButtonStyle(
                                  fixedSize: MaterialStateProperty.all(
                                      Size(75.0, 70.0)),
                                  backgroundColor: MaterialStateProperty.all(
                                      Color(0xff272B34))),
                              child: Icon(
                                CupertinoIcons.equal,
                                size: 30.0,
                                color: MaterialStateColor.resolveWith(
                                        (states) =&amp;gt; Color(0xffE78388)),
                              ),
                            ),
                          ),
                        ],
                      ),
                    ],
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The updated code introduces several new features to the calculator interface. Here's a breakdown of the changes:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Plus/Minus Button: The code includes a "±" button represented by the &lt;code&gt;CupertinoIcons.minus_slash_plus&lt;/code&gt; icon. This button allows users to toggle between positive and negative numbers, providing flexibility in performing calculations.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Percentage Button: The code introduces a "%" button, allowing users to calculate percentages easily. This button enables users to calculate values like discounts, interest rates, or any other percentage-based calculations.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Styling Changes: The code incorporates some styling changes to enhance the visual appeal and usability of the calculator. The buttons now have different background colors, making them visually distinguishable. Additionally, the icons have different colors based on their functionality, improving the overall clarity of the interface.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Additional Rows: The updated code expands the calculator interface by adding more rows of buttons. These rows include numeric buttons (0-9) and arithmetic operation buttons like addition (+), subtraction (-), multiplication (×), and division (÷). The additional buttons allow users to perform a wider range of calculations efficiently.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;By incorporating these new features and enhancements, the updated code provides users with a more comprehensive and user-friendly calculator experience.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9bmnaxh14i2pxez8cipc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9bmnaxh14i2pxez8cipc.png" alt="completed UI"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Improved Button Refactoring Enhances Code Organization and Reusability&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The code snippet provided showcases the refactoring of the calculator's button functionality into a separate class called "button." This refactoring improves code organization and promotes reusability.&lt;/p&gt;

&lt;p&gt;The "button" class is a StatelessWidget that takes a required parameter named "bname," which represents the content of the button (either text or an icon). Inside the build method, the class returns a Padding widget containing a TextButton.&lt;/p&gt;

&lt;p&gt;The appearance of the button is customized using the ButtonStyle property, which sets the fixedSize to a specific width and height (75.0, 70.0 in this case) and the backgroundColor to a dark color (0xff272B34). The content of the button, represented by the "bname" parameter, is passed to the child property of the TextButton.&lt;/p&gt;

&lt;p&gt;By encapsulating the button functionality in a separate class, it allows for better code organization and reusability. This approach makes it easier to customize button properties and enables the reuse of buttons throughout the application, providing a more modular and maintainable code structure.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Refactored code is shown below 👇&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:test123/button.dart';

class MyHomePage extends StatefulWidget {
  const MyHomePage({Key? key}) : super(key: key);

  @override
  State&amp;lt;MyHomePage&amp;gt; createState() =&amp;gt; _MyHomePageState();
}

class _MyHomePageState extends State&amp;lt;MyHomePage&amp;gt; {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: Container(
          color: Color(0xff22252D),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: [
              Container(
                height: 240.0,
                color: Color(0xff22252D),
                padding: EdgeInsets.only(top: 150.0),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.end,
                  mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                  children: [
                    Text(
                      textAlign: TextAlign.right,
                      style: TextStyle(
                        // fontWeight: FontWeight.bold,
                        fontSize: 25.0,
                        color: Colors.white,
                      ),
                      "302 x 75",
                    ),
                    Text(
                      textAlign: TextAlign.right,
                      style: TextStyle(
                        fontWeight: FontWeight.bold,
                        fontSize: 45.0,
                        color: Colors.white,
                      ),
                      "22650",
                    ),
                  ],
                ),
              ),
              Expanded(
                child: Container(
                  decoration: BoxDecoration(
                    color: Color(0xff292D36),
                  ),
                  child: Column(
                    children: [
                      Row(
                        children: [
                          button(bname:  Text(
                            "AC",
                            style: TextStyle(
                              fontSize: 25.0,
                              color: MaterialStateColor.resolveWith(
                                    (states) =&amp;gt; Color(0xff26E8C6),
                              ),
                            ),
                          ),),
                          button(bname:  Icon(
                            CupertinoIcons.minus_slash_plus,
                            size: 30.0,
                            color: MaterialStateColor.resolveWith(
                                    (states) =&amp;gt; Color(0xff26E8C6)),
                          ),),
                          button(bname: Text(
                            "%",
                            style: TextStyle(
                              fontSize: 25.0,
                              color: MaterialStateColor.resolveWith(
                                    (states) =&amp;gt; Color(0xff26E8C6),
                              ),
                            ),
                          ),),
                          button(bname: Icon(
                            CupertinoIcons.divide,
                            size: 30.0,
                            color: MaterialStateColor.resolveWith(
                                    (states) =&amp;gt; Color(0xffE78388)),
                          ),),
                        ],
                      ),
                      Row(
                        children: [
                          button(bname: Text(
                            "7",
                            style: TextStyle(
                              fontSize: 25.0,
                              color: MaterialStateColor.resolveWith(
                                    (states) =&amp;gt; Colors.white,
                              ),
                            ),
                          ),),
                          button(bname: Text(
                            "8",
                            style: TextStyle(
                              fontSize: 25.0,
                              color: MaterialStateColor.resolveWith(
                                    (states) =&amp;gt; Colors.white,
                              ),
                            ),
                          ),),
                          button(bname: Text(
                            "9",
                            style: TextStyle(
                              fontSize: 25.0,
                              color: MaterialStateColor.resolveWith(
                                    (states) =&amp;gt; Colors.white,
                              ),
                            ),
                          ),),
                          button(bname: Icon(
                            CupertinoIcons.multiply,
                            size: 30.0,
                            color: MaterialStateColor.resolveWith(
                                    (states) =&amp;gt; Color(0xffE78388)),
                          ),),
                        ],
                      ),
                      Row(
                        children: [
                          button(bname: Text(
                            "4",
                            style: TextStyle(
                              fontSize: 25.0,
                              color: MaterialStateColor.resolveWith(
                                    (states) =&amp;gt; Colors.white,
                              ),
                            ),
                          ),),
                          button(bname: Text(
                            "5",
                            style: TextStyle(
                              fontSize: 25.0,
                              color: MaterialStateColor.resolveWith(
                                    (states) =&amp;gt; Colors.white,
                              ),
                            ),
                          ),),
                          button(bname: Text(
                            "6",
                            style: TextStyle(
                              fontSize: 25.0,
                              color: MaterialStateColor.resolveWith(
                                    (states) =&amp;gt; Colors.white,
                              ),
                            ),
                          ),),
                          button(bname: Icon(
                            CupertinoIcons.minus,
                            size: 30.0,
                            color: MaterialStateColor.resolveWith(
                                    (states) =&amp;gt; Color(0xffE78388)),
                          ),),
                        ],
                      ),
                      Row(
                        children: [
                          button(bname: Text(
                            "1",
                            style: TextStyle(
                              fontSize: 25.0,
                              color: MaterialStateColor.resolveWith(
                                    (states) =&amp;gt; Colors.white,
                              ),
                            ),
                          ),),
                          button(bname: Text(
                            "2",
                            style: TextStyle(
                              fontSize: 25.0,
                              color: MaterialStateColor.resolveWith(
                                    (states) =&amp;gt; Colors.white,
                              ),
                            ),
                          ),),
                          button(bname: Text(
                            "3",
                            style: TextStyle(
                              fontSize: 25.0,
                              color: MaterialStateColor.resolveWith(
                                    (states) =&amp;gt; Colors.white,
                              ),
                            ),
                          ),),
                          button(bname:  Icon(
                            CupertinoIcons.plus,
                            size: 30.0,
                            color: MaterialStateColor.resolveWith(
                                    (states) =&amp;gt; Color(0xffE78388)),
                          ),),
                        ],
                      ),
                      Row(
                        children: [
                          button(bname: Icon(
                            CupertinoIcons.restart,
                            size: 30.0,
                            color: MaterialStateColor.resolveWith(
                                    (states) =&amp;gt; Colors.white),
                          ),),
                          button(bname: Text(
                            "0",
                            style: TextStyle(
                              fontSize: 25.0,
                              color: MaterialStateColor.resolveWith(
                                    (states) =&amp;gt; Colors.white,
                              ),
                            ),
                          ),),
                          button(bname: Text(
                            ".",
                            style: TextStyle(
                              fontSize: 25.0,
                              color: MaterialStateColor.resolveWith(
                                    (states) =&amp;gt; Colors.white,
                              ),
                            ),
                          ),),
                          button(bname: Icon(
                            CupertinoIcons.equal,
                            size: 30.0,
                            color: MaterialStateColor.resolveWith(
                                    (states) =&amp;gt; Color(0xffE78388)),
                          ),),
                        ],
                      ),
                    ],
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';

class button extends StatelessWidget {
  var bname;
  button({required this.bname});
  @override
  Widget build(BuildContext context) {
    return Padding(
          padding: EdgeInsets.only(left: 20.0, top: 10.0),
          child: TextButton(
            onPressed: () {
              print("ac");
            },
            style: ButtonStyle(
                fixedSize: MaterialStateProperty.all(
                    Size(75.0, 70.0)),
                backgroundColor: MaterialStateProperty.all(
                    Color(0xff272B34))),
            child: bname
          ),
        );
  }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>flutter</category>
      <category>development</category>
      <category>uidesign</category>
    </item>
  </channel>
</rss>
