Thanks to visit codestin.com
Credit goes to github.com

Skip to content

165369 - support other widget states for CupertinoButton #166088

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

Merged
merged 7 commits into from
May 1, 2025

Conversation

srivats22
Copy link
Contributor

This PR is a continuation of #164196. With this PR other widget states such as pressed, and focused have been added to cupertino button. This will resolve the following issue: #165369

Pre-launch Checklist

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

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: cupertino flutter/packages/flutter/cupertino repository labels Mar 27, 2025
@dkwingsmt dkwingsmt changed the title 165369 - support other widget states 165369 - support other widget states for CupertinoButton Mar 27, 2025
final Set<WidgetState> states = <WidgetState>{if (!enabled) WidgetState.disabled};
final Set<WidgetState> states = <WidgetState>{
if (!enabled) WidgetState.disabled,
if (widget.onPressed != null || widget.onLongPress != null) WidgetState.pressed,
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure about this? If I understand correctly these are the callbacks, so you're evaluating whether the user wants to listen to the gestures, while the state is about whether the button is pressed.

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 wanted a clarification on that actually... so for the pressed state how should I determine it? Was confused on that...

Copy link
Contributor

Choose a reason for hiding this comment

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

I think _tapInProgress is a perfect indicator. Although you might want to wrap every change of _tapInProgress in a setState because they currently aren't and you need setState to reevaluate the cursor.

Copy link
Contributor Author

@srivats22 srivats22 Mar 27, 2025

Choose a reason for hiding this comment

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

I see _tapInProgress was recently introduced... let me sync my local with upstream and use that to determine if the state is pressed or not. That would work right?

Or if I need to wrap everything in setState would that be a bigger change?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, just wrap every _tapInProgress = xxx in a setState.

@dkwingsmt dkwingsmt self-requested a review April 2, 2025 18:33
@dkwingsmt
Copy link
Contributor

Hi, @srivats22 , have you been able to make progress on it? Is there any blocker or anything I can help with?

@srivats22
Copy link
Contributor Author

Hi, @srivats22 , have you been able to make progress on it? Is there any blocker or anything I can help with?

Hi @dkwingsmt,
Have been super busy with few other things I will push few changes by today if possible...
Thank you

@srivats22
Copy link
Contributor Author

Have one question:
I am writing the test for testing the pressed state can you please review if this is right, its failing for me on my machine:

await tester.pumpWidget(buildButton(enabled: true, cursor: const _ButtonMouseCursor()));
await tester.tap(find.byType(CupertinoButton));
if(tapInProgress){
      // await gesture.moveTo(tester.getCenter(find.byType(CupertinoButton)));
      await tester.pump();
      expect(
        RendererBinding.instance.mouseTracker.debugDeviceActiveCursor(1),
        SystemMouseCursors.grab,
    );
}
class _ButtonMouseCursor extends WidgetStateMouseCursor {
  const _ButtonMouseCursor();

  @override
  MouseCursor resolve(Set<WidgetState> states) {
    return const WidgetStateProperty<MouseCursor>.fromMap(<WidgetStatesConstraint, MouseCursor>{
      WidgetState.disabled: SystemMouseCursors.forbidden,
      WidgetState.pressed: SystemMouseCursors.grab,
      WidgetState.focused: SystemMouseCursors.copy,
      WidgetState.any: SystemMouseCursors.basic,
    }).resolve(states);
  }

  @override
  String get debugDescription => '_ButtonMouseCursor()';
}

@srivats22
Copy link
Contributor Author

Was able to resolve the pressed state test have updated everything now

Copy link
Contributor

@dkwingsmt dkwingsmt left a comment

Choose a reason for hiding this comment

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

Generally good except for a few minor issues.

@victorsanni victorsanni self-requested a review April 16, 2025 23:06
Copy link
Contributor

@victorsanni victorsanni left a comment

Choose a reason for hiding this comment

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

LGTM once @dkwingsmt's comments are addressed.

@srivats22
Copy link
Contributor Author

What seems to have caused the Windows test to fail? I went through the logs and wasn't able to find anything related to cuperino_button.test unless I overlooked something

@dkwingsmt
Copy link
Contributor

Seems like timeout with flake. I've rerun.

@dkwingsmt dkwingsmt added the autosubmit Merge PR when tree becomes green via auto submit App label Apr 17, 2025
@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Apr 17, 2025
Copy link
Contributor

auto-submit bot commented Apr 17, 2025

autosubmit label was removed for flutter/flutter/166088, because This PR has not met approval requirements for merging. The PR author is not a member of flutter-hackers and needs 2 more review(s) in order to merge this PR.

  • Merge guidelines: A PR needs at least one approved review if the author is already part of flutter-hackers or two member reviews if the author is not a flutter-hacker before re-applying the autosubmit label. Reviewers: If you left a comment approving, please use the "approve" review action instead.

@srivats22
Copy link
Contributor Author

Looks like auto submit failed cause of no approvals...

Copy link
Contributor

@dkwingsmt dkwingsmt left a comment

Choose a reason for hiding this comment

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

LGTM!

@dkwingsmt dkwingsmt requested a review from victorsanni April 23, 2025 18:19
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 1, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 2, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 3, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 3, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 4, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
f: cupertino flutter/packages/flutter/cupertino repository framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants