Skip to content

avoid_logic_in_view_classes #58844

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

Closed
IvanDembicki opened this issue Aug 30, 2022 · 2 comments
Closed

avoid_logic_in_view_classes #58844

IvanDembicki opened this issue Aug 30, 2022 · 2 comments
Labels
devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. linter-lint-request needs-info We need additional information from the issue author (auto-closed after 14 days if no response)

Comments

@IvanDembicki
Copy link

This rule will help separate view classes from controllers, data models, etc.
Classes that extend base view classes should not contain logic, except for factory constructors. All logical operators should be prohibited in this classes.

class NoLogicView extends StatelessWidget {
  const NoLogicView(this.model);
  
  factory NoLogicView.create(TestModel model) {
    if (model.enabled) return NoLogicViewEnabledChild(); // No error Avoid logic in view classes 
    return NoLogicViewDisabledChild();
  }
  
  final TestModel model;

  @override
  Widget build(BuildContext context) {
    return Container(
      color: model.enabled ? Colors.red : Colors.grey, // Error Avoid logic in view classes 
      child: Row(
        children: [
          if (model.enabled) const SizedBox(height: 10), // Error Avoid logic in view classes
          Container(
            color: containerColor, 
          ),
        ],
      ),
    );
  }
  
  Color get containerColor => model.enabled ? Colors.red : Colors.grey; // Error Avoid logic in view classes 
  
}

class TestModel {
  bool enabled = false;
}

NoLogicView noLogicView = NoLogicView(TestModel());

@srawlins
Copy link
Member

@IvanDembicki thanks for the request. Can you explain what specific rules the lint would enforce? Can a class which extends StatelessWidget have any instance members other than build? instance fields are allows? Static members? Are there other "view classes"?

@srawlins srawlins added the needs-info We need additional information from the issue author (auto-closed after 14 days if no response) label Nov 23, 2022
@github-actions
Copy link

github-actions bot commented Dec 7, 2022

Without additional information we're not able to resolve this issue, so it will be closed at this time. You're still free to add more info and respond to any questions above, though. We'll reopen the case if you do. Thanks for your contribution!

@github-actions github-actions bot closed this as completed Dec 7, 2022
@devoncarew devoncarew added devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. labels Nov 19, 2024
@devoncarew devoncarew transferred this issue from dart-archive/linter Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. linter-lint-request needs-info We need additional information from the issue author (auto-closed after 14 days if no response)
Projects
None yet
Development

No branches or pull requests

3 participants