Created with <3 with dartpad.dev.
Created
May 11, 2023 20:42
-
-
Save dander11/30cd27ba70d9393a0ef8be83145da2c7 to your computer and use it in GitHub Desktop.
illustrious-marble-0069
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 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