Building a Simple Flutter App: A Beginner’s Guide

Precious Adedokun - Feb 14 - - Dev Community

Introduction

Flutter is a powerful UI toolkit by Google that allows developers to build natively compiled applications for mobile, web, and desktop from a single codebase. In this guide, we’ll walk through creating a simple Flutter app to help beginners get started.

Step 1: Setting Up Your Flutter Environment

Before we start coding, ensure you have Flutter installed on your system.

Installation Steps:

  1. Download and install the Flutter SDK (Official Guide).

  2. Install an editor like VS Code or Android Studio.

  3. Set up an emulator or connect a physical device.

  4. Run the following command to check if everything is set up correctly:

flutter doctor

Step 2: Creating Your First Flutter Project

Once Flutter is set up, create a new project using:

flutter create my_first_app
cd my_first_app
flutter run

This command generates a basic Flutter project with all necessary files.

Step 3: Understanding the Folder Structure

lib/: Contains the main Dart code.

pubspec.yaml: Manages dependencies and assets.

android/ & ios/: Platform-specific configurations.

Step 4: Building a Simple UI

Let’s modify the lib/main.dart file to create a basic counter app.

Code Example:

import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: CounterApp(),
    );
  }
}

class CounterApp extends StatefulWidget {
  @override
  _CounterAppState createState() => _CounterAppState();
}

class _CounterAppState extends State<CounterApp> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Flutter Counter App')),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text('You have pressed the button this many times:'),
            Text('$_counter', style: TextStyle(fontSize: 30, fontWeight: FontWeight.bold)),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        child: Icon(Icons.add),
      ),
    );
  }
}
Enter fullscreen mode Exit fullscreen mode

Step 5: Running the App

Run the app using:

flutter run
Enter fullscreen mode Exit fullscreen mode

Your app should now display a counter that increases each time you press the button.

Next Steps

  • Customize the UI by adding colors and different fonts.
  • Learn about Stateful and Stateless Widgets.
  • Try adding a text input field or additional buttons.

In Conclusion

Building your first Flutter app is an exciting step in mobile development. Keep experimenting, and soon you'll be creating more complex applications.

💬 What will you build next? Let me know in the comments!

Please follow @apcodesphere for more Tech based Updates, With Web an app development insights.
His social media pages
https://www.Tiktok.com/@apcodesphere
https://www.instagram.com/apcodesphere
https://www.x.com/apcodesphere

. . .