Welcome to the world of Flutter and Dart! This tutorial aims to guide you through the first steps of building a Flutter app using Dart.
By the end of this tutorial, you will have a basic understanding of Dart programming, Flutter's framework, how to set up your development environment, and how to create a simple Flutter app.
Prerequisites:
For Dart, most Flutter installations also install Dart, so you don't need to install Dart separately.
We recommend using Visual Studio Code or Android Studio. Both IDEs have excellent Flutter and Dart plugins.
flutter create my_app
, replace my_app
with your desired project namecd my_app
flutter run
// Importing Flutter's Material Design package
import 'package:flutter/material.dart';
// The main() function is the entry point of our app
void main() {
runApp(MyApp()); // Running our custom-made app
}
// Creating a stateless widget
class MyApp extends StatelessWidget {
// A widget that describes part of the user interface
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Hello World App'), // App bar title
),
body: Center(
child: Text('Hello World!'), // Display text in the center
),
),
);
}
}
When you run this code, you'll see a new app with an app bar titled 'Hello World App', and a center text that displays 'Hello World!'.
We've introduced you to Dart, Flutter, and the necessary steps to create your first Flutter app. You've learned how to install the Flutter SDK, setup your IDE, and create a basic Flutter app that displays "Hello World!".
Exercise 1: Modify the 'Hello World' app to display 'Welcome to Flutter'.
Exercise 2: Add a button to the app. When pressed, the button should change the text displayed in the center of the screen.
Exercise 3: Create an app that has two screens. The first screen should have a button that navigates to the second screen.
Solutions can be found on the official Flutter documentation: https://flutter.dev/docs. We recommend trying to solve the exercises on your own before looking at the solutions.
Happy Fluttering!