A useful widget has a clear job. It accepts the information it needs and describes how that information should appear. Keeping the inputs explicit makes the widget easier to reuse and reason about.
Give a widget an input
This card receives a name. It does not fetch a profile or store an account. Those responsibilities can stay elsewhere.
import 'package:flutter/material.dart';
void main() => runApp(const MaterialApp(
home: Scaffold(body: Center(child: WelcomeCard(name: 'Mira'))),
));
class WelcomeCard extends StatelessWidget {
const WelcomeCard({super.key, required this.name});
final String name;
@override
Widget build(BuildContext context) => Card(
child: Padding(
padding: const EdgeInsets.all(24),
child: Column(mainAxisSize: MainAxisSize.min, children: [
const Icon(Icons.waving_hand, size: 40),
const SizedBox(height: 12),
Text('Hello, $name', style: Theme.of(context).textTheme.headlineSmall),
const Text('What will you build today?'),
]),
),
);
}Stateless does not mean never rebuilt
A StatelessWidget does not own a separate mutable State object. Its parent can still rebuild it with different inputs. The build method should describe the interface from those inputs and the surrounding context.
Choose a useful boundary
Extract a widget when a part of a screen has a name, a purpose or repeated behavior. Splitting every Padding into its own file usually adds navigation without adding understanding.
Trace inputs from the parent to the child
The parent constructs WelcomeCard with a name. That constructor input becomes a final field, and build reads it to produce the greeting. The card does not need to know whether the name came from a form, local storage or a network request. Keeping that source outside the widget makes the component easier to reuse and test.
Now imagine the parent rebuilds with another name. The card can render the new input even though it is a StatelessWidget. Stateless means there is no separate mutable State object owned by this widget; it does not mean its visible output can never change.
When extracting a component, write its inputs first. If the widget needs to tell the parent about an action, accept a callback rather than reaching into a global variable. Compare this with local state : the owner changes the data, while a smaller display widget can remain a straightforward description of its inputs.
Try it yourself
Add a second required input called message. Display two cards with different names and messages. Neither card should depend on global variables.