flutter / flutter/flutter-intellij

Return generic Widget instead of specific widget during extract method

Open
#5,591 5 comments 3 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
2k
Forks
356
Avg merge
1d 11h
Merged PRs (30d)
27

Description

Currently when you use the `Refactor -> Extract Method` option, it creates a method with root Widget item return-type. e.g:
```
Widget build(BuildContext context){
return Scaffold
body: Container(
child: Text('Hi'),
),
);
}
````

Now if you extract the `Container` it creates such a method for you:
```
Widget build(BuildContext context){
return Scaffold
body: _buildContainer(),
);
}

Container _buildContainer(){
return Container(
child: Text('Hi'),
);
}
```

**The problem** is that in many cases we wrap the root widget into another (for example in this scenario, in a `ClipRRect`, so it's better to have a generic `Widget` type as return-type:
```
Widget build(BuildContext context){
return Scaffold
body: _buildContainer(),
);
}

Widget _buildContainer(){
return Container(
child: Text('Hi'),
);
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.