How to call a List with Strings to make the call dynamic

user18355990

I'm searching for create a dynamic form which contain DropDownButtons.

Before do that, I'm trying something on DartPad to know if it's possible to call a list with some Strings.

Below an example about what I want to do (maybe what I'm searching for is now possible) :

void main() {
  List<Map<String, String>> listOf3AInitial = [{"name": "4A"},
                                               {"name": "5A"}
                                              ];
  
  String _listOf = "listOf";
  String _year = "3A";
  String _type = "Initial";
  
  
  var listOfType = "$_listOf$_year$_type";
  
  
  print(listOfType);
}

In this case it print "listOf3AInitial" and I want to print the List {"name": "4A"},{"name": "5A"}.

How it is possible to do that ?

Regards

Kaushik Chandru

You have to map a string of it's value to do so. For example

List<Map<String, String>> listOf3AInitial = [{"name": "4A"}, {"name": "5A"}];

Map<String, List<Map<String, String>>> list3AInitialMap = {
   "listOf3AInitial" : listOf3AInitial,
   }; 

Now you can get a value from this map like

String _listOf = "listOf";
  String _year = "3A";
  String _type = "Initial";
  
  
  var listOfType = "$_listOf$_year$_type";
  print(list3AInitialMap[listOfType]);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related