Skip to content

avoid_returning_widgets #59498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jesperu7 opened this issue Aug 6, 2024 · 3 comments
Open

avoid_returning_widgets #59498

jesperu7 opened this issue Aug 6, 2024 · 3 comments
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. devexp-linter Issues with the analyzer's support for the linter package linter-lint-request linter-status-pending P3 A lower priority bug or feature request type-enhancement A request for a change that isn't a bug

Comments

@jesperu7
Copy link

jesperu7 commented Aug 6, 2024

Description:
The avoid_returning_widgets rule would ensure that widgets are not returned from functions. Instead, widgets should be created within the build method or in dedicated widget classes. This practice enhances code readability, maintainability, and performance. By enforcing this rule, we can encourage developers to structure their Flutter applications in a more modular and understandable manner.

Rationale:

Maintainability: Keeping widget creation within the build method or dedicated widget classes makes the code easier to maintain.
Performance: Proper widget creation helps optimize performance by ensuring that the widget tree is managed efficiently.
Clarity: Improves the readability and clarity of the code, making it easier for developers to understand and work with.

Example:

Bad:

Widget createButton() {
  return ElevatedButton(
    onPressed: () {},
    child: Text('Press Me'),
  );
}

Good:

class CustomButton extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return ElevatedButton(
      onPressed: () {},
      child: Text('Press Me'),
    );
  }
}
@bwilkerson bwilkerson transferred this issue from dart-archive/lints Aug 6, 2024
@bwilkerson
Copy link
Member

@goderbauer

@goderbauer
Copy link
Contributor

This seems to be a duplicate of #58303. There's some discussion there and what I said there is still accurate.

@NatoBoram
Copy link

It's also still addressed in the proposal

@srawlins srawlins added the type-enhancement A request for a change that isn't a bug label Aug 30, 2024
@devoncarew devoncarew added devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. labels Nov 20, 2024
@devoncarew devoncarew transferred this issue from dart-archive/linter Nov 20, 2024
@pq pq added the P3 A lower priority bug or feature request label Nov 20, 2024
@bwilkerson bwilkerson added area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. and removed legacy-area-analyzer Use area-devexp instead. labels Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. devexp-linter Issues with the analyzer's support for the linter package linter-lint-request linter-status-pending P3 A lower priority bug or feature request type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

7 participants