Skip to content

Instantly share code, notes, and snippets.

@channainfo
Last active November 14, 2020 03:43
Show Gist options
  • Save channainfo/fbd761f1239b341541b67c78ec83ee71 to your computer and use it in GitHub Desktop.
Save channainfo/fbd761f1239b341541b67c78ec83ee71 to your computer and use it in GitHub Desktop.
Map with index dart extension
import 'package:flutter_test/flutter_test.dart';
import 'package:vtenh/extensions/list_map_with_index_extension.dart';
void main() {
group('.mapWithIndex', () {
test('return a new list from map value and index as original Int type', () {
List<int> items = [20, 30, 40];
List<int> result = items.mapWithIndex((value, index) => index * 2);
expect(result.length, 3);
expect(result[0], 0);
expect(result[1], 2);
expect(result[2], 4);
});
test('return a new list from map value and index as String type', () {
List<int> items = [20, 30, 40];
List<String> result = items.mapWithIndex((value, index) => "${index * 2}");
expect(result.length, 3);
expect(result[0], '0');
expect(result[1], '2');
expect(result[2], '4');
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment