There is a delightfully sardonic anti-pattern in coding known as the pyramid of doom. This pattern describes code that is excessively nested (such as 10+ nested if statements and control flow loops). You end up getting code that, when you look at it from a distance, resembles a pyramid. Pyramid-like code is highly bug-prone. It is hard to read and, more importantly, hard to maintain.
Widget trees are not immune to this deadly pyramid. In this chapter, we've tried to keep our widget trees fairly shallow, but none of the examples so far is really indicative of production code—they are simplified scenarios to explain the fundamentals of Flutter. The tree only grows deeper from here.
To fight the pyramid of doom, we're going to use a weapon known as refactoring. This is a process of taking code that is not written ideally and updating the code without changing its functionality. We can take our n-layer deep widget trees...