9

The meta package provides a @protected annotation (besides others) to get analyzer hints or warnings about the use of protected members outside of direct subclasses.

INFO: The member 'selectedChildrenChanged' can only be used within instance members of subclasses of 'MenuItem' ([bwu_ng_quick_nav] test/menu_item_test.dart:108)

I'm not interested in these hints in my unit tests.

How can I suppress such hints?

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567

1 Answers1

12

The suppression code for the @protected hint is INVALID_USE_OF_PROTECTED_MEMBER. Add a suppression comment like:

  // ignore: INVALID_USE_OF_PROTECTED_MEMBER
  app.quickNav.keyDownHandler(ctrlKeyDown);

or

   // ignore_for_file: INVALID_USE_OF_PROTECTED_MEMBER

The codes for other hints can be found in

or in the source code

This works with Dart VM version: 1.16.0-edge. I don't know with what version this was released.

Hopefully these IDs will be part of the warnings soon to not have to look them up.

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
  • 2
    Updated link to the hint codes: https://github.com/dart-lang/sdk/blob/master/pkg/analyzer/lib/src/error/codes.dart – KOGI Mar 03 '17 at 01:49
  • 1
    Please update your links, they contain only imports now. Thank you. – Martin Braun Jun 06 '22 at 18:39
  • 1
    [Newly updated link](https://github.com/dart-lang/sdk/blob/74fb9e190fa1ff7c5cf1334488bd46dcc91d09bd/pkg/analyzer/lib/src/error/error_code_values.g.dart) to hints and error codes: – KOGI Mar 13 '23 at 23:56