3

How to get the class names of the child elements of the class carousel in dart in the form of an array??

<div class="carousel">
      <div class="galleryCars">
      ....
      </div>
      <div class="galleryCars2">
      ....
      </div>
      <div class="galleryCars3">
      ....
      </div>
      <div class="galleryCars4">
      ....
      </div>
</div>
K Walrath
  • 300
  • 3
  • 10
Kiran Kumar
  • 1,610
  • 3
  • 16
  • 22

2 Answers2

5

Here's how to get a Set of children class names :

query('.carousel').children.expand((e) => e.classes).toSet();
Alexandre Ardhuin
  • 71,959
  • 15
  • 151
  • 132
4

Quick n dirty:

var carousel = query(".carousel");
var classList = [];
carousel.children.forEach((childElement) => classList.addAll(childElement.classes));
print(classList); // [galleryCars,galleryCars2,galleryCars3,galleryCars4]
Chris Buckett
  • 13,738
  • 5
  • 39
  • 46
  • Whats that 's' used for?? Is that 'e' or 's'? – Kiran Kumar Aug 19 '13 at 09:28
  • I tried this method but its not printing or alerting the class names. I am new to dart and couldnt find the problem. – Kiran Kumar Aug 19 '13 at 12:24
  • I've created a gist with the files I'm using here: https://gist.github.com/chrisbu/6268607 - the Dart `print()` statement goes back to the dart editor or console rather than appearing in the browser UI (print is like log messages) – Chris Buckett Aug 19 '13 at 12:31