Hello World on Flutter

Open the lib/main.dart file. Replace the contents with the following code:

import 'package:flutter/material.dart';

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

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

Explanation:

  • main() is the entry point of the Flutter app.

  • MaterialApp creates the basic structure of the app.

  • Scaffold provides an app bar and body structure.

  • Text widget displays "Hello, World!" in the center.

Updated on