Introduction

Welcome to this step-by-step guide on building your first mobile app with Flutter. Flutter is a UI toolkit from Google that allows you to natively compile applications for mobile, web, and desktop from a single codebase. In this tutorial, we will focus on building a simple mobile app.

Setting Up Your Development Environment

Before we start coding, we need to set up our development environment. Here are the steps:

Creating a New Flutter Project

Once your development environment is set up, you can create a new Flutter project. Open your terminal or command prompt and run the following command:

flutter create my_first_app

This will create a new Flutter project in a directory called “my_first_app”.

Understanding the Flutter Project Structure

A Flutter project has a specific directory structure. Here’s a brief overview:

  • lib: This is where your Dart code lives.
  • test: This directory is for testing your application.
  • android: Contains Android-specific code.
  • ios: Contains iOS-specific code.
  • pubspec.yaml: This file is used to manage Dart packages for your project.

Building Your First Screen

Now, let’s start building our app. Open the main.dart file in the lib directory and replace the existing code with the following:


import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('My First App'),
        ),
        body: Center(
          child: Text('Hello, Flutter!'),
        ),
      ),
    );
  }
}

This code creates a simple app with an app bar and a centered text widget.

Running Your App

To run your app, use the following command in your terminal:

flutter run

Congratulations! You’ve just built and run your first Flutter app. Keep practicing and exploring more features of Flutter.