Issue
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.
Solution
I ended up settling for making the information part of a class.
class ChosenLevel {
String level;
bool overallToggled = false;
Map categories = {
'Style': true,
'MelodyHarmony': false,
'RhythmTempo': false,
'TextureStructureForm': false,
'Timbre': false,
};
Color _color;
ChosenLevel(this.level, this._color);
get categoriesNumber {
return categories.length;
}
specificCategory(index) {
switch (index) {
case 0:
return 'Style';
case 1:
return 'MelodyHarmony';
case 2:
return 'RhythmTempo';
case 3:
return 'TextureStructureForm';
case 4:
return 'Timbre';
/* default:
throw ("Something strange happend"); */
}
}
toggleCat(c) {
this.categories['${c}'] = !this.categories['${c}'];
}
toggleLevel() {
this.overallToggled = !this.overallToggled;
}
@override
String toString() {
return '{${level}, ${categories}}';
}
}
Answered By – Ankere
Answer Checked By – Jay B. (FlutterFixes Admin)