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.
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 lazyIterableobject which is then immediately iterated to construct aList. This incurs an unnecessary memory allocation overhead during thebuildmethod, which can be called up to 60 or 120 times per second during animations.Proposed Solution
Use Dart's collection
forloop combined with the spread operator. This avoids the intermediate iterable allocation and reads much cleaner for UI trees.Before:
After:
Areas affected
MongoStatsViewExtensionStatsViewQueryaDropdown