0
0
Fluttermobile~5 mins

Why everything in Flutter is a widget

Choose your learning style9 modes available
Introduction

Flutter uses widgets for everything because it makes building apps simple and consistent. Widgets are like building blocks that create the app's look and behavior.

When you want to create a button, text, or image on the screen.
When you need to arrange items in rows, columns, or grids.
When you want to change how something looks or behaves, like adding color or padding.
When you want to build a complete screen or page in your app.
When you want to handle user interactions like taps or scrolls.
Syntax
Flutter
Widget build(BuildContext context) {
  return WidgetName();
}
Every visible part of the app is a widget, from text to layout containers.
Widgets can be combined to create complex interfaces.
Examples
A simple widget that shows text on the screen.
Flutter
Text('Hello World')
A container widget that adds padding and background color around a text widget.
Flutter
Container(
  padding: EdgeInsets.all(10),
  color: Colors.blue,
  child: Text('Inside a container'),
)
A column widget that arranges two text widgets vertically.
Flutter
Column(
  children: [
    Text('Line 1'),
    Text('Line 2'),
  ],
)
Sample App

This app shows a simple screen with a colored box and text inside. Every part you see is a widget: the app bar, container, text, and layout.

Flutter
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('Widgets Everywhere')),
        body: Center(
          child: Container(
            padding: EdgeInsets.all(20),
            color: Colors.amber,
            child: Text('Everything is a widget!'),
          ),
        ),
      ),
    );
  }
}
OutputSuccess
Important Notes

Widgets are easy to reuse and combine, making app design flexible.

Understanding widgets helps you control every part of your app's look and feel.

Summary

Flutter uses widgets as the basic building blocks for everything you see and interact with.

Widgets can be simple like text or complex like entire screens.

Learning widgets helps you create beautiful and responsive apps.