Skip to content

Refactor: Replace .map().toList() in UI builders with Spread operator and for loops #530

Description

@ZhuchkaTriplesix

Description

We have multiple UI components that use the .map((item) => Widget(item)).toList() pattern to generate a list of children.

Why is this a problem?

Calling .map().toList() creates an intermediate lazy Iterable object which is then immediately iterated to construct a List. This incurs an unnecessary memory allocation overhead during the build method, which can be called up to 60 or 120 times per second during animations.

Proposed Solution

Use Dart's collection for loop combined with the spread operator. This avoids the intermediate iterable allocation and reads much cleaner for UI trees.

Before:

children: chips.map((c) => _buildChip(cs, c)).toList(),

After:

children: [ 
  for (final c in chips) _buildChip(cs, c), 
],

Areas affected

  • MongoStatsView
  • ExtensionStatsView
  • QueryaDropdown
  • Other UI components where lists are generated.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions