Skip to content

Instantly share code, notes, and snippets.

@dander11
Created May 11, 2023 20:43
Show Gist options
  • Select an option

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

Select an option

Save dander11/c089c8c8d89538f37b8f18cebfc7cfb1 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 printNavigationItem() {
print(toString());
}
}
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 childrens = <NavigationItem>[];
for (var i = 0; i < 10; i++) {
childrens.add(
NavigationItem(
label: "name" + i.toString(),
url: "testingURL",
children: [],
),
);
}
parents.add(NavigationItem(
children: childrens, 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