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

Stable Diffusion WebUI 1.10.1 Full Installation Guide | AUTOMATIC1111 | Windows 11

Stable Diffusion WebUI 1.10.1 Full Installation Guide | AUTOMATIC1111 | Windows 11  Welcome to this step-by-step Stable Diffusion WebUI 1.10.1 installation guide! In this tutorial, we will walk you through the complete setup process on Windows 11 , including downloading and installing Git , setting up Python 3.10.6 , cloning the AUTOMATIC1111 repository , and configuring .gitignore for a clean and efficient installation. By following this guide, you’ll be able to generate AI-generated images using Stable Diffusion with ease. Whether you're new to AI image generation or an experienced user, this guide ensures that your setup is optimized for performance and stability. 🔗 Required Downloads: Before we begin, make sure to download the following tools: ✅ Git for Windows – Download Here ✅ Stable Diffusion WebUI (AUTOMATIC1111) – Download Here ✅ Python 3.10.6 – Download Here 🛠️ Step-by-Step Installation Process 1️⃣ Install Git for Windows Git is required to clone the ...

Unreal Engine Product Showcase: Mesmerizing Video Sequence Render

  4k Image:

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 ...