How can I retrieve this information as when I am testing it using print it is returning the following error?
I have searched online to try and find a solution but alas for the past 30 minutes i have not been able to find one. If there is an easier and more efficient way of storing information then please let me know.
Apologies as I am still learning dart, moving from JS.
List<Object> chosenSelection = [
[
'Advanced Higher', //[0][0]
false /**Enabled? */, //[0][1]
[
'Style',
'MelodyHarmony',
'RhythmTempo',
'TextureStructureForm',
'Timbre',
] /**Categories */, //[0][2][0-4]
],//[0]
[
'Higher', //[0][0]
false /**Enabled? */, //[0][1]
[
'Style',
'MelodyHarmony',
'RhythmTempo',
'TextureStructureForm',
'Timbre',
] /**Categories */, //[0][2][0-4]
]
];
print(chosenSelection[0][0]); //Output: 'Advanced Higher'
print (chosenSelection[0][2][4]); // Output 'Timbre'
Resulting error: type '_InternalLinkedHashMap<dynamic, dynamic>' is not a subtype of type 'List' of 'function result'
I am trying to access the data 'Advanced Higher' and then 'Timbre' within the variable.
CodePudding user response:
I'm not sure what's the question here, but this code doesn't compile for 2 reasons:
- You're missing a closed bracket in the second print;
- You're trying to access the elements of an Object as if it is a nested List.
CodePudding user response:
You are trying to implement a 2d and 3d list. But you have declared a 1d list.
In order to declare a 2d list you need to declare it as List<List<Object>>
and for a 3d list: List<List<List<Object>>>
So you need to declare List<List<List<Object>>> chosenSelection
, and then
print(chosenSelection[0][0]); //Output: 'Advanced Higher'
print (chosenSelection[0][2][4]); // Output 'Timbre'