Dart List Convert to Map Using Index

Dart List Convert to Map Using Index :

Dart List Convert to Map Using Index
import 'package:enumerable/enumerable.dart';

void main() {
  //add dependency: enumerable
  final list = ['one', 'two', 'three'];

  final result1 = list.select$1((element, index) => MapEntry(index, element));
  print(result1);

  final result2 = list
      .select$1((element, index) => MapEntry(index, element))
      .toMap$1((kv) => kv.key, (kv) => kv.value);
  print(result2);

  var index = 0;
  final result3 = list.toMap((key) => index++);
  print(result3);
}

Output

MapEntry(0: one), MapEntry(1: two), MapEntry(2: three))
{0: one, 1: two, 2: three}
{0: one, 1: two, 2: three}

The flutter tutorial  is a website that bring you the latest and amazing resources of code. All the languages codes are included in this website. The languages like flutter, android, java,kotlin etc.with the help of this languages any user can develop the beautiful application

For more information about Flutter. visit www.fluttertutorial.in