Posts

Showing posts from October, 2020

The Unbearable Lightness of BuildContext

Image
Overview In this post I'd like to write about Flutter's BuildContext, as a mechanism to enable communication throughout the whole widget tree. The idea came to me while trying to explain a fix to a friend, and soon I realized how there was so much more behind it than the fix. I believe that contexts are very important when it comes to mobile development, as they are one of the building blocks of it. So this post shows a real life error and how to solve it, but its main focus is on the idea underlying the fix, the BuildContext. The problem Say you've added the navigation drawer to your app, following the recommended tutorial . @override Widget build(BuildContext context) { return Scaffold( drawer: Drawer( child: ListView( padding: EdgeInsets.zero, children: [ DrawerHeader( child: Text('Drawer Header'), decoration: BoxDecoration( color: Colors.blue, ), ...