vandadnp / flutter-tips-and-tricks

A Collection of Flutter and Dart Tips and Tricks

Home Page:https://linktr.ee/vandadnp

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"Converting Lists to Maps in Dart" should use literals

iapicca opened this issue · comments

43 - Converting Lists to Maps in Dart

const list = ['this','is','a','long','text'];

final map = {for (final s in list) s:s.length}; /// <= this way!

void main() {
  for (final e in map.entries) {
    print('"${e.key}" length is ${e.value}');
  }
}