How to build dynamic lists of widgets?

This is one of the most common issues faced by Flutter developers.

Indeed, the List literal is not easy to work with and creating a complex list can be a painful experience — be it conditionally adding a widget in a Column or concatenating a children argument with custom logic.

As such, it is not uncommon to find code that looks like this:

Do you have trouble reading this example? Don’t worry, me too.

This horror is due to a combination of facts:

  • Dart does not have a spread operator


Building blocks made smaller

You’ve likely heard of Flutter. And you probably know how powerful widgets are. But they have an issue: they require a good amount of boilerplate.

Let’s analyze our typical widget:

11 lines for a simple Text with arguments is a lot! Due to using classes, we have many duplicates and unnecessary bits of code:

  • Each parameter is declared twice

Functions would be a perfect fit. It makes the syntax much shorter:

Almost perfect right?

Well, no. Functions have…

Remi Rousselet

A software engineer passionated in Flutter. You’ll find me most of the time on stackoverflow answering Flutter related questions.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store