Call us USA (+1)312-698-3083 | Email : sales@wappnet.com

Beginners Guide to Building First Flutter App

Introduction

Flutter is becoming a popular choice among developers due to its time-saving benefits. Developers may instantly create apps for iOS and Android without having to write code individually. Development is more efficient when using a single codebase for Android, iOS, web, and desktop. “Hot reload” enables quick code change viewing, speeding up debugging. Flutter’s widget library makes creating attractive UIs simple. Flutter provides simplicity and performance, whether you have expertise with cross-platform solutions or are new to app development.

What is Flutter?

Flutter offers customizable widgets for visually appealing UIs and features like “hot reload” for quick code changes preview.”Hot reload” allows for faster development by applying code changes immediately. Flutter, known for its outstanding performance and cross-platform compatibility, is a popular choice for contemporary, scalable app development with a robust community. Flutter’s model and library support, together with Skia’s smooth animations, make it suitable for contemporary, scalable cross-platform apps.

Why Developers Choose Flutter for App Development?

Single codebase for multiple platforms: Write once and deploy anywhere with a single codebase across several platforms.

Hot Reload: View updates instantly without erasing the current state of the application.

Rich pre-built widgets: Make stunning user interfaces with little work.

High Performance: Machine code is directly compiled from Flutter.

Growing Communities and Ecosystems: Great support, plugins, and documentation.

Cost Efficiency: With shorter development cycles and a single codebase, you may save time and money.

List of Essential Widgets that help in Flutter App Development

  1. Container: A versatile widget for layout, decoration, and positioning of child widgets.
  2. Row: Place child widgets horizontally in a single line.
  3. Column: Arrange the child widgets vertically in one column.
  4. Text: Shows a string of text with custom style.
  5. Stack: Overlays widgets on top of each other, allowing for more sophisticated UI layouts.
  6. ListView: ListView is a vertical or horizontal scrollable list of widgets.
  7. GridView: Shows a grid of widgets that may scroll vertically and horizontally.
  8. Padding: Creates space around a widget to customize its layout and spacing.
  9. Scaffold: Provides a basic structure for a page, including app bar, body, and floating action buttons.
  10. Icon: Shows scalable icons that may be adjusted in size and color.
  11. Expanded: Expands a widget to occupy the available area within a Row, Column, or Flex.
  12. SizedBox: A box having a fixed width and height, useful for spacing or managing widget size.
  13. InkWell: A touch-sensitive widget that responds to taps; commonly used for buttons.
  14. AppBar: A material-design app bar that can display titles, icons, and actions.
  15. Image: Shows an image from the assets, network, or memory.
  16. Form: Forms serve as containers for user input fields and validation.
  17. ElevatedButton: A button widget with elevation, useful for actions like submitting forms.
  18. TextField: A widget for user input, typically used for forms or search fields.
  19. FlutterLogo: Displays Flutter’s logo, often used for branding or demonstrations.
  20. Flexible: Allows a widget to flexibly resize within a Row or Column based on available space.
banershape

Looking to Hire a Dedicated Flutter Developers?

Wappnet provide dedicated flutter developers for hire. Our expert developers have extensive experience in building applications tailored to meet your specific business needs.

How to Set Up the Flutter Development Environment?

Flutter is a powerful framework for building cross-platform apps for mobile, web, and desktop. As a leading flutter app development company with the help of experienced flutter developers we are sharing here the generalized steps to set up the development environment for creating Flutter apps on any platform, followed by one example to get you started.

1. Install Flutter SDK

Flutter provides a unified codebase that allows you to build apps for Android, iOS, web, and desktop. To start, you need to install the Flutter SDK.

Steps:

Download Flutter SDK: Visit the official Flutter website flutter.dev and download the SDK for your operating system (Windows, macOS, or Linux).

Extract SDK: Extract the downloaded file to your desired location on your system.

Add Flutter to PATH:

  • Windows: Add the flutter/bin directory to your system’s PATH environment variable.
  • macOS/Linux: Add this line to your shell configuration file (.bashrc, .zshrc, etc.):

export PATH=”$PATH:`pwd`/flutter/bin”

2. Install a Code Editor

Flutter supports several IDEs, but the most commonly used ones are Visual Studio Code and Android Studio.

Visual Studio Code (VS Code):

  • Install VS Code.
  • Install the Flutter and Dart extensions from the Extensions Marketplace for easy development.

Android Studio:

  • Install Android Studio.
  • During installation, choose the Flutter plugin, and ensure you install the Dart SDK as well.

3. Set Up Mobile Development (Android & iOS)

To develop for Android and iOS, you’ll need platform-specific setup:

Android:
Install Android SDK: This is included with Android Studio. Ensure that Android Studio is fully installed and configured.

Set Up Device or Emulator: Use a physical Android device or configure an Android emulator from Android Studio. Enable developer mode and USB debugging on your device.

iOS:
macOS Required: Developing for iOS requires macOS and Xcode.

Install Xcode: Install Xcode from the Mac App Store.

Set Up Simulator: Use the iOS Simulator available in Xcode or a physical device (requires signing up for an Apple Developer account).

4. Set Up Web Development

Flutter allows you to create web applications by running Flutter code in the browser. Firstly, make sure that you have Chrome installed. Secondly, run the following command to enable web development in Flutter:

flutter config –enable-web

Lastly, you can choose Chrome as the target device in your IDE when running your Flutter app.

5. Set Up Desktop Development (Windows, macOS, Linux)

To build desktop applications, Flutter provides support for Windows, macOS, and Linux.

Enable desktop support with the following command:

flutter config –enable-windows-desktop
flutter config –enable-macos-desktop
flutter config –enable-linux-desktop

Ensure you have the necessary development tools:

  • Windows: Requires Visual Studio for building Windows apps.
  • macOS: Xcode is required to build macOS apps.
  • Linux: GTK libraries are required to build Linux apps.

6. Verify Flutter Setup

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

flutter doctor

This command will check for any missing dependencies and list actions required to complete the setup.

Create a Basic Flutter App

Now that your environment is set up, let’s create a basic Flutter app that works across mobile, web, and desktop platforms.

Step 1:
Open your terminal (or IDE’s  terminal) and run the following command:

flutter create my_first_flutter_app

Step 2:
Navigate into your project directory:

cd my_first_flutter_app

Step 3:
Open the project in your preferred IDE (Android Studio, Visual Studio Code, etc.).

Basic Flutter App Development Structure

lib/main.dart: The entry point of your Flutter app.

android/: Contains Android-specific files.

ios/: Contains iOS-specific files.

windows/: Contains Windows-specific files.

macos/: Contains macOS-specific files.

linux/: Contains Linux-specific files.

web/: Contains Web-specific files.

pubspec.yaml: The configuration file for managing dependencies and assets.

Build the User Interface (UI)

Flutter relies heavily on widgets to create the UI. There are two types of widgets:

  • Stateless Widgets: These do not change their state once built.
  • Stateful Widgets: These can rebuild themselves based on internal state changes.

Let’s replace the default code in lib/main.dart with a simple UI.

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 Flutter App’),

),

body: Center(

child: Text(

‘Hello, Flutter!’,

style: TextStyle(fontSize: 24),

),

),

),

);

}

}

Here, we are using Flutter’s built-in Material Design components (MaterialApp, Scaffold, and AppBar) to structure the app, and the Text widget to display text.

Adding Interactivity

Now let’s make the app interactive by adding a button that updates the text.

  1. Convert the MyApp widget from a StatelessWidget to a StatefulWidget.
  2. Update the lib/main.dart code to add interactivity:

import ‘package:flutter/material.dart’;

void main() {

runApp(MyApp());

}

class MyApp extends StatefulWidget {

@override

_MyAppState createState() => _MyAppState();

}

class _MyAppState extends State {

String text = ‘Hello, Flutter!’;

void updateText() {

setState(() {

text = ‘You pressed the button!’;

});

}

@override

Widget build(BuildContext context) {

return MaterialApp(

home: Scaffold(

appBar: AppBar(

title: Text(‘My First Flutter App’),

),

body: Center(

child: Column(

mainAxisAlignment: MainAxisAlignment.center,

children: [

Text(

text,

style: TextStyle(fontSize: 24),

),

SizedBox(height: 20),

ElevatedButton(

onPressed: updateText,

child: Text(‘Press Me’),

),

],

),

),

),

);

}

}

Now, when the button is pressed, the text changes dynamically.

Step 3:
Run the app

Mobile: Connect an Android or iOS device (or use an emulator), and run the app with:

flutter run

Web: Ensure web is enabled (flutter config –enable-web) and run with:

flutter run -d chrome

Desktop: Ensure desktop support is enabled, and run the app with:

flutter run -d windows    # for Windows
flutter run -d macos      # for macOS
flutter run -d linux      # for Linux

Conclusion

In conclusion, building your first Flutter app is an exciting journey that opens up a manifold new possibilities for developers. In case any other detailed information is required, discover our blogs or contact us, and our Flutter app developers will guide you.

Ankit Patel
Ankit Patel
Ankit Patel is the visionary CEO at Wappnet, passionately steering the company towards new frontiers in artificial intelligence and technology innovation. With a dynamic background in transformative leadership and strategic foresight, Ankit champions the integration of AI-driven solutions that revolutionize business processes and catalyze growth.

Related Post