1
votes

For Example In a Collection there are 10 or more Documents I want to create the list of that collection according to the DocumentsId and the list contains only values not keys.

Document 1-->

    'Num1':'1',
    'Num2':'2',
    'Num3': '3',
    'Num4': '4',
    'Num5': '5',
    'Num6': '6',
    'Num7': '7',
    'Num8': '8',
    'Num9': '9',
    'Num10': '10',

Document 2-->

    'Num1':'1',
    'Num2':'2',
    'Num3': '3',
    'Num4': '4',
    'Num5': '5',
    'Num6': '6',
    'Num7': '7',
    'Num8': '8',
    'Num9': '9',
    'Num10': '10',

The list be like this for every Document List document1 = [1,2,3,4,5,6,7,8,9,10] List document2 = [11,12,13,14,15,16,17,18,19,20] And the every list name is the documentid

1

1 Answers

1
votes

Assuming the 'Collection' is a simple map object you can do:

Map temp= { 'Num1':'1',
'Num2':'2',
'Num3': '3',
'Num4': '4',
'Num5': '5',
'Num6': '6',
'Num7': '7',
'Num8': '8',
'Num9': '9',
'Num10': '10',};
 var newList=temp.values.toList();

If it is a custom object you can use the map method :

myobjectList.map((object)=>object.id).toList();

It will iterate all the elements in the collection and 'map' every one to the property you need.

EDIT:

Dinamically you cannot change a variable name, but you can change a variable attributes. What you wish can be achieved as:

List<List<int>> documents;
//access each document by its index
List document1 = [1,2,3,4,5,6,7,8,9,10]
documents[0]//would be equal to accessing  document1

OR use a map:

Map map={document.name:[1,2,3,4,5]};
map['document2']=[6,7,8,9,10];