Knowledgebase

Flutter Widgets and Composition Print

  • mobiledevelopment, mobile, guide, howto, solution, zillionkinghost, hosting, support
  • 0

Building interfaces.

WHAT A WIDGET IS

An immutable description of part of the interface.

WHAT THE TWO KINDS ARE

Stateless, depending only on its configuration Stateful, holding state that changes over time

WHAT HAPPENS ON A STATE CHANGE

The build method runs again, producing a new description.

WHAT THE FRAMEWORK DOES

Compares descriptions and updates only what changed.

WHAT COMPOSITION MEANS HERE

Behaviour added by wrapping, rather than by configuring one widget with many options.

WHAT THAT PRODUCES

Deeply nested widget trees, which surprise newcomers.

WHAT TO DO ABOUT DEPTH

Extract widgets into named classes.

WHY CLASSES RATHER THAN METHODS

The framework can then skip rebuilding them when nothing changed.

WHAT KEYS DO

Preserve identity when widgets move or reorder.

WHEN THEY MATTER

Lists that reorder, and widgets holding state.

WHAT TO USE FOR LONG LISTS

The builder variants, creating only visible items.

WHAT TO AVOID

Very large build methods Heavy computation in build Rebuilding large subtrees for a small change


Was this answer helpful?
Back

Are you happy with your experience? Leave us a review on Trustpilot.


Trustpilot