Introduction to Flutter
Flutter is Google's open-source UI toolkit for building natively compiled mobile from a single codebase. It uses the Dart programming language and provides a fast development cycle with its hot reload feature, a rich set of customizable widgets, and native performance.
Installing Flutter
01. Download Flutter for your operating system.
02. Set up your preferred IDE (VS Code or Android Studio).
03. Connect a device or emulator to test your application.
Lets start by creating a simple Flutter app that prints "Hello World" on the screen.
Create New Project Using VS Code
Go to View > Command Palette (Ctrl / Cmd + Shift + P)
Type flutter
Select the Flutter: New Project
1// Importing the Flutter material package2import 'package:flutter/material.dart';34// The main function is the entry point for every Flutter app.5void main() {6runApp(const MainApp()); // Calls the MainApp widget to start the app7}89// Creating a StatelessWidget. This widget does not change state.10class MainApp extends StatelessWidget {11const MainApp({super.key});1213@override14Widget build(BuildContext context) {15// The MaterialApp widget sets up the app and its theme16return MaterialApp(17debugShowCheckedModeBanner: false, //Removes debug banner18home: Scaffold( // Scaffold provides the basic structure for the app19appBar: AppBar( // AppBar widget for the top app bar20title: const Text('Hello World App'),21),22body: const Center( // Center widget centers the text23child: Text('Hello World'), // Text widget displays the text24),25),26);27}28}
Key Takeaways
- Every Flutter app starts with the main() function.
- runApp() initializes the widget tree and starts the app.
- Scaffold provides the basic structure, including an app bar and a body section.
©2024 Codeblockz
Privacy Policy