4 ms·
> it would be great if you all can say something about how you can get over / stay sane with the staircase looking nesting of code blocks and how you manage to
by heavyset_go 6y ago
> it would be great if you all can say something about how you can get over / stay sane with the staircase looking nesting of code blocks and how you manage to keep it all in your head to navigate the code base.
The same way you would in any other code base, with the ample use of names and modules, and breaking nested components and logic into their own classes and functions.
The problem is that it requires discipline, or at least a standard style guide, to adhere to. It's similar to JavaScript in that regard, where bad practices can seemingly be ignored or even encouraged.
- runeks 6y agoI gotta say that I miss some from of let-binding, so I don't have to choose between (a) local variables plus newline-separated statements, including "return", wrapped in {}, and (b) the lovely syntax of `Widget build = (context) => ...`. E.g. instead of writing Widget helloWidget(BuildContext context) { final db = Provider.of<MyDatabase>(context, listen: false); return Row( children: <Widget>[ Text("Hello, "), FutureBuilder<String>( future: db.username, builder: (ctx, snapshot) => snapshot.hasData ? Text(snapshot.data) : CircularProgressIndicator(), ), ] ); } i'd like to write: Widget helloWidget = (BuildContext context) => let db = Provider.of<MyDatabase>(context, listen: false) in Row( children: <Widget>[ Text("Hello, "), FutureBuilder<String>( future: db.username, builder: (ctx, snapshot) => snapshot.hasData ? Text(snapshot.data) : CircularProgressIndicator(), ), ] );
- cutler 6y agoTrouble is that in most Flutter code the widget staircase is idiomatic. Swift UI also seems to have chosen the same path.
- heavyset_go 6y agoYou're downvoted, but I agree. It's unfortunate, but that is why I say that discipline or an enforced style guide is required.
- solarkraft 6y agoI don't really see the issue. Widget layouts are trees. Why shouldn't you represent them as such in your declarative code?