Skip to main content

Flutter Dart Tutorial: Building a Simple Counter App | Learn Flutter from Scratch

Title: Flutter Dart Tutorial: Building a Simple Counter App | Learn Flutter from Scratch




Description: 

In this Flutter Dart tutorial, we'll walk through the process of creating a simple counter app from scratch. You'll learn how to set up a basic Flutter project, use Material Design components, and implement stateful widgets to build a functional counter that increments with the press of a button. Whether you're a beginner or looking to enhance your Flutter skills, this step-by-step guide will help you understand the fundamentals of Flutter and Dart programming.

In this Flutter Dart code walkthrough, we'll explore the construction of a basic counter app. The code begins with the main entry point, initiating a Flutter application using the runApp method with the MyApp widget. The MyApp widget, a stateless widget, configures the application's metadata, such as the title and theme. Within the app, there's a stateful widget called MyHomePage, responsible for managing the state of the counter. The state is maintained in the _MyHomePageState class, which extends the State class. This class includes a counter variable (_counter) initialized to 0 and a method (_incrementCounter) to update the counter using Flutter's setState function. The user interface is built using the Scaffold widget, featuring an AppBar with the title 'DEV1'. The body of the app is a centered column containing two text widgets. The first text widget displays a message, and the second dynamically shows the current counter value using a themed headline style. A floating action button (FloatingActionButton) triggers the _incrementCounter method when pressed, incrementing the counter and updating the UI. This example provides a hands-on introduction to key Flutter concepts, including widgets, state management, and basic user interface elements. Follow along with the code to understand how Flutter and Dart work together to create a responsive and interactive mobile app. Happy coding!

Tags:

- Flutter Dart

- Flutter Tutorial

- Dart Programming

- Mobile App Development

- Flutter Counter App

- Stateful Widgets

- Material Design

- Flutter for Beginners

- Learn Flutter from Scratch

- Flutter Development 


Main.dart:

import 'package:flutter/material.dart';


void main(){

  runApp(MyApp());

}


class MyApp extends StatelessWidget {

  @override

  Widget build(BuildContext) {

    return MaterialApp(

      debugShowCheckedModeBanner: false,

      title: 'DEV1',

      theme: ThemeData(

        primarySwatch: Colors.blue,

      ),

      home: MyHomePage(),

    );

  }

}


class MyHomePage extends StatefulWidget {

  @override 

  _MyHomePageState createState() =>

_MyHomePageState();

}


class _MyHomePageState extends State<MyHomePage> {

  int _counter = 0;

   

  void _increamnetCounter(){

    setState(() {

      _counter++;

    });

  }

  @override

  Widget build(BuildContext context){

    return Scaffold(

      appBar: AppBar(

        title: Text('DEV1'),

      ),

      body: Center(

        child: Column(

          mainAxisAlignment: MainAxisAlignment.center,

          children: <Widget>[Text('You have clicked the button many times.'),

          Text(

              '$_counter',

              style: Theme.of(context).textTheme.headline4,

            ),

          ],

        ),

      ),

      floatingActionButton:

      FloatingActionButton(

          onPressed: _increamnetCounter,

          tooltip: 'Increment',

          child: Icon(Icons.add),

        ),

    );

  }

}


pubspec.yaml:

name: dev1

description: A new Flutter project.

publish_to: 'none'

version: 0.1.0


environment:

  sdk: '>=3.1.4 <4.0.0'


dependencies:

  flutter:

    sdk: flutter


dev_dependencies:

  flutter_test:

    sdk: flutter

  flutter_lints: ^2.0.0


flutter:

  uses-material-design: true


GitHub Link:
https://github.com/Sivatech24/Flutter-Dart-Simple-Counter-App.git

Thank You...

Comments

Popular posts from this blog

Install TensorFlow on Windows 11: Step-by-Step Guide for CPU & GPU

 --- Installing **TensorFlow on Windows 11** requires setting up system dependencies, configuring Python, and ensuring compatibility with CPU or GPU acceleration. This step-by-step guide provides everything needed to install **TensorFlow 2.10 or lower** on **Windows Native**, including software prerequisites, Microsoft Visual C++ Redistributable installation, Miniconda setup, GPU driver configuration, and verification steps.   ### **System Requirements:**   Before installing TensorFlow, ensure your system meets these requirements:   - **Operating System:** Windows 7 or higher (64-bit)   - **Python Version:** 3.9–3.12   - **pip Version:** 19.0 or higher for Linux and Windows, 20.3 or higher for macOS   - **Microsoft Visual C++ Redistributable:** Required for Windows Native   - **Long Paths Enabled:** Ensure long paths are enabled in Windows settings   For **GPU support**, install:   - **NVIDIA ...

Unreal Engine Product Showcase: Mesmerizing Video Sequence Render

  4k Image:

Cloudflare Is Down Worldwide: What Happened, What It Means & What You Can Do

🌍 Cloudflare Is Down Worldwide: What Happened & Why the Internet Broke Today On 18 November 2025 , the internet experienced one of the largest global outages in years as Cloudflare , the backbone of countless websites and online services, went down unexpectedly. The outage caused millions of websites to become slow, unreachable, or return 5xx internal server errors , leading to widespread disruption across businesses, apps, and essential online platforms. This blog post explains what happened, why the internet broke for many users, and what Cloudflare has officially said so far. What Exactly Happened? Around 4:30 PM IST , reports began flooding social media and outage trackers like Downdetector. Users across India, Europe, the US, and Southeast Asia noticed that: Websites were not loading Requests were timing out Services dependent on Cloudflare CDN or DNS stopped responding APIs hosted through Cloudflare were failing Even some security and protection layers were ...