There are two extraction techniques that we highlighted in this recipe that bear delving deeper into:
- Extract method
- Extract widget
The first technique should be relatively straightforward. The Dart Analysis Server will inspect all the elements of your highlighted code and simply pull it out into a new method in the same class.
You have code like this:
class RefactoringExample extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Column(
children: <Widget>[
Row(
children: <Widget>[
Text('Widget A'),
Text('Widget B'),
],
),
Row(
children: <Widget>[
Text('Widget C'),
Text('Widget D'),
],
),
],
);
}
}
You can go one step further beyond extracting and also simplify the code as well. Both of these rows have the same widget structure, but their text is different. You...