Created with <3 with dartpad.dev.
Last active
May 11, 2023 20:53
-
-
Save dander11/2ec0ffa8dc7a59f9263d9f8f65b76949 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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