Skip to content

Instantly share code, notes, and snippets.

@dander11
Last active May 11, 2023 20:53
Show Gist options
  • Select an option

  • Save dander11/2ec0ffa8dc7a59f9263d9f8f65b76949 to your computer and use it in GitHub Desktop.

Select an option

Save dander11/2ec0ffa8dc7a59f9263d9f8f65b76949 to your computer and use it in GitHub Desktop.
class NavigationItem {
final String url;
final String label;
final List<NavigationItem> children;
NavigationItem({
required this.url,
required this.children,
required this.label,
});
@override
String toString() {
var output = "$label: $url\n";
for (var child in children) {
output += "\t-- ${child.toString()}";
}
return output;
}
}
void printAllExceptTopLevel(NavigationItem top) {
for (var child in top.children) {
print(child.toString());
}
}
void main() {
var parents = <NavigationItem>[];
for (int j = 0; j < 5; j++) {
var children = <NavigationItem>[];
for (var i = 0; i < 10; i++) {
children.add(
NavigationItem(
label: "name ${i.toString()}",
url: "testingURL",
children: [],
),
);
}
parents.add(NavigationItem(
children: children, label: "parent ${j.toString()}", url: "testing",));
}
var top =
NavigationItem(children: parents, label: "Top level", url: "testing",);
printAllExceptTopLevel(top);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment