Repository: flutter
Issue: Decorators experiment
Labels: c: new feature,P3,team-framework,triaged-framework

### Background

Flutter apps are composed from a tree of widgets.

For example:

```dart
Center(
 child: ColoredBox(
   color: Colors.amber,
   child: Padding(
     padding: EdgeInsets.all(8.0),
     child: Text('Hello world'),
   ),
 ),
),
```

This results in the following widget tree:

```
Center
└── ColoredBox
   └── Padding
       └── Text
```


This coding style where the widget tree is created by nesting widgets is generally viewed as a strength of Flutter, however, we've heard that in some cases the source code can be a bit verbose due to heavy nesting. Decorators are an experiment for how we might address this.

### Experiment

The "decorators" experiment adds an alternative syntax focused on basic styling widgets, such as adding padding or centering a widget. With the decorators syntax you can wrap a widget with another styling widget.

For example:

```dart
Text('Hello world')
 .padding(EdgeInsets.all(8.0))
 .coloredBox(Colors.amber)
 .center()
```

These decorators _do not_ modify the `Text` widget. Instead, these wrap the `Text` widget in a `Padding` widget, then wraps that in a `ColoredBox` widget, and then finally wraps that in a `Center` widget.

This creates the same widget tree as before:

```
Center
└── ColoredBox
   └── Padding
       └── Text
```

### Frequently asked questions

#### Will decorators replace existing widgets?
No! We're only adding a new tool to your toolbox, you can stick to nested widgets if that's what you prefer. We won't deprecate or remove existing widgets. The decorators will likely be placed in a separate library with its own import, and will thus be opt-in.

#### Does the order of decorators matter?
Just like nested widgets, the order of decorators matter. However, the order of decorators is _inverted_ from the order of nested widgets. We like to say that nested widgets are "inside out", whereas decorators are "outside in".

#### Will I be able to  create my own decorators?
Yup!

#### Do decorators use new Dart language features?
No, decorators are plain Dart code that use the existing [extension methods](https://dart.dev/language/extension-methods) language feature.

#### How will decorators impact my app's performance?
We expect the performance impact of decorators to be negligible.

#### Where does the 'decorators' name come from?
Decorators are used to, well, decorate your app's UI using the [decorator pattern](https://en.wikipedia.org/wiki/Decorator_pattern).

#### How can I get updates on the decorators experiment?
We'll post updates to this issue. Stay tuned!

#### How can I give feedback on this proposal?
You can go ahead and comment on this issue.

### Open questions

We'd like to evaluate the following:

1. Do decorators improve the overall development experience of Flutter?
2. Do decorators improve code readability?
3. Do decorators improve code writability?
4. Do decorators make it harder to learn Flutter?

We'd love to hear your feedback on this experiment. Feel free to share
your thoughts, suggestions, or questions on this thread!