Components (Widgets)
The fundamental building blocks of UI in Flutter.
Everything in Flutter is a widget. From a simple Text element to an entire Scaffold. You build your UI by composing widgets into a tree. Creating your own reusable widgets is a core principle for keeping your code DRY (Don't Repeat Yourself) and maintainable.
Code Example
import 'package:flutter/material.dart';
class CustomButton extends StatelessWidget {
final String text;
final VoidCallback onPressed;
const CustomButton({
Key? key,
required this.text,
required this.onPressed,
}) : super(key: key);
@override
Widget build(BuildContext context) {
return ElevatedButton(
onPressed: onPressed,
child: Text(text),
);
}
}