All three of them do basically the same thing. What are the best practices? In which case shall I use which extracting way? What is the standard?
I guess these could be some points that could matter:
- readability
- performance
- number of lines
Example:
Extract the Container. Which way would you prefer and why?
class Example extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container();
}
}
1. Extract Container as Widget (+6 lines):
class Example extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ExtractedAsWidget();
}
}
class ExtractedAsWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Container();
}
}
2. Extract Container as Method (+1 (in some cases 3) line):
class Example extends StatelessWidget {
@override
Widget build(BuildContext context) {
return buildContainer();
}
Container buildContainer() => Container();
}
3. Extract Container as Variable (+1 line):
class Example extends StatelessWidget {
@override
Widget build(BuildContext context) {
var container = Container();
return container;
}
}