flutter
  1. flutter-first-application

Flutter First Application

Syntax

To create a Flutter First Application, follow these steps:

  1. Open Android Studio or Visual Studio Code and create a new Flutter project.
  2. Modify the lib/main.dart file to create your first Flutter application.

Example

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

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

Output

The above example will create a basic Flutter application with a title and a centered text that says "Hello, World!"

Explanation

The code imports the flutter/material.dart package, which contains widgets and classes specific to the Material Design guidelines.

The void main() function is the entry point for the app and calls the MyApp class that extends the StatelessWidget class.

The build() method returns a MaterialApp widget that is the root of the app and sets the title property.

The home property of the MaterialApp widget is a Scaffold widget that contains an AppBar and a Center widget.

The AppBar widget sets the title of the app, and the Center widget displays the text "Hello, World!".

Use

This basic Flutter application template can be used as a starting point for any Flutter project.

Important Points

  • Flutter applications are built using widgets and classes specific to the Material Design guidelines.
  • The entry point for a Flutter application is the main() function.
  • The MaterialApp widget is the root of a Flutter application and sets the title property.
  • The Scaffold widget provides a basic structure for a Flutter app and contains an AppBar and a body property.
  • The Center widget is used to center its child widget.

Summary

In this page, we learned how to create a basic Flutter application using the Material Design guidelines. We discussed the syntax, example, output, explanation, use, important points, and overall summary of creating a Flutter First Application.

Published on: