← Flutter tutorial

Flutter

StatelessWidget

A StatelessWidget describes UI that doesn't change over time, given the same inputs, it always looks the same.

Example: a reusable stateless widget

class GreetingCard extends StatelessWidget {
  final String name;
  const GreetingCard({super.key, required this.name});

  @override
  Widget build(BuildContext context) {
    return Text('Hello, $name!');
  }
}

Defines a reusable widget that displays "Hello, {name}!", e.g. GreetingCard(name: 'Ada') renders "Hello, Ada!".

You define it as a class extending StatelessWidget, and override its build() method to return the widget tree. Notice name is declared final, from the Dart tutorial's Variables lesson, since a stateless widget's data, by definition, never changes after it's built.

Example
class GreetingCard extends StatelessWidget {
  final String name;
  const GreetingCard({super.key, required this.name});

  @override
  Widget build(BuildContext context) {
    return Text('Hello, $name!');
  }
}
Output
Defines a reusable widget that displays "Hello, {name}!" — e.g. GreetingCard(name: 'Ada') renders "Hello, Ada!".
Ready to go further?

These free tutorials are a preview of what a Code Secure Academy cohort covers, project work and all.

Explore our tracks

Cookie preferences

Choose what you're comfortable with. You can change this any time from the footer.

Don't miss out

Ready to build something real?

Create a free account to enroll in a track, and get notified the moment a cohort opens.

Create free account