by harikb · 6y ago · 0 comments
I started my career writing single threaded Palm OS apps (64k limit) - there was like 10 possible widgets with 5 possible events on each widget and rest of it was application code. Mobile app development is a different beast now. Yes, I sound like old-man-yelling-at-cloud. Is this table-stakes for all UI and App development?
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.
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(),
),
]
);I found i was over this fear in days if not hours, and continued to improve with my ongoing discovery of helpful UI components. Furthermore, defining your own components and breaking out inline functions into proper functions in your UI classes goes a long way, too.
Android Studio, if you use it (i didn't), auto-appends closing bracket comments to keep you visually aware of your nesting. For the reasons i stated, i don't think it is as important as you might think.
If you haven't tried Flutter, particularly for syntactical reasons, i would urge you dip your toes in.
So does VS Code. I stared writing my first Flutter app a couple of weeks ago. I’m using VS Code and I have to say the IDE support is pretty great.
Regarding syntax and nesting levels, what I don’t is the `git diff` from wrapping the top-most expression in a new class, thus causing everything inside/below it to be indented further, even though only a single class was added. So e.g. wrapping an outer Column in a SingleChildScrollView causes everything inside the column to change in the diff because of added indentation.
I’ve seen some horribly large components that would be much better if split up.
Google should really advise this.