Skip to content

Return generic Widget instead of specific widget during extract method #5591

Description

@alizera

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'),
        );
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions