Google Dart Only Show Specific DropDown Child Elem

2019-03-06 18:32发布

问题:

I'm attempting to get only certain values from a drop-down by hiding a select few. Apparently I cannot go over an array index of 3 or nothing shows up and obviously not below an index of 0. I'm trying to hide the first three choices in the drop-down. Any ideas would be appreciated. Please let me know if you need more information.

The printout:

  1. Select a choice --disabled
  2. Choice 1
  3. Choice 2
  4. Choice 3
  5. Choice 4
  6. Choice 5

Code:

  List<Map> _predefinedFilterList;
_predefinedFilterList = jsonObject["jsonResponse"] as List<Map>;

for (Map filterMap in _predefinedFilterList) {
        dropDownEl.children.add(new OptionElement(data: filterMap["displayName"]));

print("Test: "+filterMap["displayName"]);

 //         dropDownEl.children[0].hidden = true;   
 //         dropDownEl.children[1].hidden = true;
//          dropDownEl.children[2].hidden = true;
      }

回答1:

This would only go over the items after the 3rd as sublist would remove the first 3 list elements.

_predefinedFilterList.sublist(3).forEach((map) => print(map["displayName"]));


回答2:

What about just clearing the children and then only add these you want to show?