Skip to content

Conversation

@Piinks
Copy link
Contributor

@Piinks Piinks commented May 4, 2021

Follow up to #81569

This is not a breaking change, but as it involves deprecating something, I will be following up with a migration guide. :)

This deprecates the old PointerDeviceKind filter that has been replaced with the supportedDevices set. This allows folks to filter allowed gestures for more than one type. This also adds dart fixes for all of the associated classes to assist migration.

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@Piinks Piinks added c: new feature Nothing broken; request for a new capability framework flutter/packages/flutter repository. See also f: labels. f: gestures flutter/packages/flutter/gestures repository. a: desktop Running on desktop a: mouse Issues related to using a mouse or mouse support labels May 4, 2021
@google-cla google-cla bot added the cla: yes label May 4, 2021
#TODO(Piinks): update these with PR number once opened

# Changes made in https://github.com/flutter/flutter/pull/TBD
- title: "Migrate to 'supportedDevices'"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔

@Piinks
Copy link
Contributor Author

Piinks commented May 4, 2021

Oh, there are a few more classes I should apply this change to, marking WIP while I add those in.

@Piinks Piinks changed the title Deprecate GestureDetector.kind in favor of new supportedDevices [WIP] Deprecate GestureDetector.kind in favor of new supportedDevices May 4, 2021
@Piinks Piinks changed the title [WIP] Deprecate GestureDetector.kind in favor of new supportedDevices Deprecate GestureDetector.kind in favor of new supportedDevices May 4, 2021
@Piinks
Copy link
Contributor Author

Piinks commented May 4, 2021

Well that escalated quickly. 😜
This is ready for review now.

});

testWidgets('ForecePressGestureRecognizer asserts when kind and supportedDevices are both set', (WidgetTester tester) async {
try {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pattern seems unsafe. Consider if ForcePressGestureRecognizer accidentally had the asset deleted. Then there would be no error to catch and the test would just pass as is.

consider:

expect(() => ForcePressGestureRecognizer(
    kind: PointerDeviceKind.touch,
    supportedDevices: <PointerDeviceKind>{ PointerDeviceKind.touch },
  ), throwsA(isA<AssertionError>().having((e) => e.toString(), 'description',  contains('kind == null || supportedDevices == null'))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I forgot to add the fail state at the end of the try statement. I like yours better. Maybe we should update other tests that are like this, I've forgotten the fail state before, and seen others do the same. Thanks! 🙏

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@a14n Is this pattern lintable to suggest the throwsA pattern over the error-prone try/catch pattern in tests?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Running such a lint on flutter doesn't detect any similar case. So I don't think it's common enough to justify the existence/maintenance of this lint.

Copy link
Contributor

@a14n a14n May 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, I made a mistake in my test. There are actually cases where it triggers.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I found several cases (a PR will be sent soon) but there are false positives that are hard to detect. So the lint should not be that useful.

this.dragStartBehavior = DragStartBehavior.down,
}) : assert(dragStartBehavior != null),
super(debugOwner: debugOwner, kind: kind);
assert(kind == null || supportedDevices == null),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you rely on the assert in the superclass by passing the arguments straight through (unmodified) to super()?

(here and elsewhere)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error messages (and accompanying stack traces) may be slightly clearer if the assert happens as early as possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going back and forth on exactly that. Earlier error/stack trace or simpler code... I'm happy to do either. Curious what folks think about the either/or.
Since the parameters are the same for the super and sub classes (kind/supportedDevices), maybe an error on the super class would not be that obscure @goderbauer WDYT?

@Piinks
Copy link
Contributor Author

Piinks commented May 6, 2021

I've updated with the feedback re: tests and assertions. PTAL. :)

Copy link
Contributor

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@fluttergithubbot
Copy link
Contributor

This pull request is not suitable for automatic merging in its current state.

  • The status or check suite Google testing has failed. Please fix the issues identified (or deflake) before re-applying this label.
  • The status or check suite Windows framework_tests_libraries has failed. Please fix the issues identified (or deflake) before re-applying this label.

@Piinks
Copy link
Contributor Author

Piinks commented May 7, 2021

Confirmed the G testing failure is a flake, setting the check green manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: desktop Running on desktop a: mouse Issues related to using a mouse or mouse support c: new feature Nothing broken; request for a new capability f: gestures flutter/packages/flutter/gestures repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants