Skip to content
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

Implement "use_nearest_context" rule #190

Open
yurii-prykhodko-solid opened this issue Dec 19, 2024 · 0 comments
Open

Implement "use_nearest_context" rule #190

yurii-prykhodko-solid opened this issue Dec 19, 2024 · 0 comments

Comments

@yurii-prykhodko-solid
Copy link
Collaborator

Right now we have an unused_parameters rule that forces us to rename all unused parameters to underscores.

In some cases, we not use context in widget builder functions initially, and add a usage later.
There is some potential of using an incorrect instance of BuildContext that way.

We want to add a lint that checks that we use BuildContext from nearest available scope.

Example:

class SomeWidget extends StatefulWidget {
...
}

class _SomeWidgetState extends State<SomeWidget> {
  ...
  void _showDialog() {
    showModalBottomSheet(
      context: context,
      builder: (BuildContext _) {                <-- LINT -- this should be renamed to `context`
        final someProvider = context.watch<SomeProvider>();   <-- uses context from StatefulWidget instead of the builder, which causes errors.

        return const SizedBox.shrink();
      },
    );
  }
}

We also probably can provide a quick fix here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant