I\'m trying to access a class value by using a variable previously defined in dart, but I keep getting the error the operator [] isn\'t defined for the class
You can createn a toMap()
function in your Movie class and access properties using [] operator
class Movie {
String name;
String actor;
String producer;
Map toMap() {
return {
'name': name,
'actor' : actor,
'producer' : producer,
};
}
}
Now Movie class properties can be accessed as:
Movie movie = Movie();
movie.toMap()['name'];