This recipe is going to focus on taking some existing code and updating it to something more manageable. Open e_commerce_screen_before.dart and notice that the whole class is one single unbroken build method:
- The first thing we're going to do with this file is divide it up using a refactoring tool called extract method.
Move your cursor over AppBar, right-click and select Refactor | Extract Method on VS Code or Refactor | Extract | Extract Method on Android Studio to open the extract dialog. Call the method _buildAppBar and press Enter:
- Perform an extract of the first Row widget in the Column widget using the same technique. Call this method _buildToggleBar().
- The next step is going to be a bit more tricky. Collapse the code for the two next rows by tapping the collapse icon just to the right of the line numbers:
- With both rows collapsed, highlight the three SizedBox instances and the two...