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

Make CupertinoRadio's mouseCursor a WidgetStateProperty #151910

Merged
merged 10 commits into from
Jul 19, 2024

Conversation

victorsanni
Copy link
Contributor

@victorsanni victorsanni commented Jul 17, 2024

#149681 introduced mouseCursor to CupertinoRadio as a MouseCursor instead of a WidgetStateProperty to match Material Radio's mouseCursor property for .adaptive.

This PR changes mouseCursor to be of type WidgetStateProperty<MouseCursor> as per review comments in #151788 (comment).

PR bringing mouseCursor into CupertinoRadio: #149681.

Part of #58192

Pre-launch Checklist

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

@victorsanni
Copy link
Contributor Author

cc @jonahwilliams

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. f: cupertino flutter/packages/flutter/cupertino repository labels Jul 17, 2024
@victorsanni victorsanni marked this pull request as ready for review July 17, 2024 20:08
@victorsanni victorsanni changed the title Make CupertinoRadio mouseCursor a WidgetStateProperty Make CupertinoRadio's mouseCursor a WidgetStateProperty Jul 17, 2024
Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

Some quick questions, otherwise looks good.

@@ -297,7 294,7 @@ class _CupertinoRadioState<T> extends State<CupertinoRadio<T>> with TickerProvid
checked: widget._selected,
selected: accessibilitySelected,
child: buildToggleable(
mouseCursor: effectiveMouseCursor,
mouseCursor: widget.mouseCursor ?? _defaultMouseCursor,
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 set this as the actual default value for CupertinoRadio.mosueCursor or is it more complicated than that?

Comment on lines 450 to 452
mouseCursor: WidgetStateProperty.all(widget.mouseCursor
?? (kIsWeb && widget.onChanged != null
? SystemMouseCursors.click : SystemMouseCursors.basic)),
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this duplicating CupertinoRadio._defaultMouseCursor? Could you make that public and use it here?

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 added a static method defaultMouseCursor in CupertinoRadio that I just call here to get the default mouse cursor.

packages/flutter/test/cupertino/radio_test.dart Outdated Show resolved Hide resolved
@Piinks
Copy link
Contributor

Piinks commented Jul 18, 2024

Just sharing here, we synced offline that the original change was cut into the beta release that is about to go out. This should be CP'd into beta after it lands. 👍

Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

Some quick questions.

Comment on lines 141 to 143
/// If null, then [SystemMouseCursors.basic] is used when this radio button is
/// disabled. When this radio button is enabled, [SystemMouseCursors.click] is
/// used on Web, and [SystemMouseCursors.basic] is used on other platforms.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: You might just say defaults to [defaultMouseCursor] and let people look that up themselves. Or maybe it's more useful for users to see it written out like this, up to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True. Then I could move these docs to defaultMouseCursor.

///
/// See also:
///
/// * [WidgetStateMouseCursor], a [MouseCursor] that implements
/// `WidgetStateProperty` which is used in APIs that need to accept
/// either a [MouseCursor] or a [WidgetStateProperty<MouseCursor>].
final MouseCursor? mouseCursor;
/// either a [MouseCursor] or a [WidgetStateProperty].
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you remove the type annotation on WidgetStateProperty?

Copy link
Contributor Author

@victorsanni victorsanni Jul 18, 2024

Choose a reason for hiding this comment

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

I think @Piinks mentioned previously that it doesn't work with dartdoc? I might be wrong though.

Copy link
Contributor

@justinmc justinmc Jul 19, 2024

Choose a reason for hiding this comment

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

Ah makes sense, that's probably right 👍

@@ -210,6 208,13 @@ class CupertinoRadio<T> extends StatefulWidget {

bool get _selected => value == groupValue;

/// The default mouse cursor of a [CupertinoRadio].
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: "mouse cursor" => "[mouseCursor]"

/// either a [MouseCursor] or a [WidgetStateProperty<MouseCursor>].
final MouseCursor? mouseCursor;
/// either a [MouseCursor] or a [WidgetStateProperty].
final WidgetStateProperty<MouseCursor>? mouseCursor;
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if you explicitly pass null here?

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 think the null coalescing operator should make it resolve to WidgetStateProperty.all(CupertinoRadio.defaultMouseCursor(widget.onChanged)).

@@ -210,6 208,13 @@ class CupertinoRadio<T> extends StatefulWidget {

bool get _selected => value == groupValue;

/// The default mouse cursor of a [CupertinoRadio].
static MouseCursor defaultMouseCursor(Function? onChanged) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be an actual WidgetStateProperty<MouseCursor> instead of a function that returns a MouseCursor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The mouseCursor property of Material Radio is nullable, so to pass it to WidgetStateProperty<MouseCursor>? which is the type of CupertinoRadio's mouseCursor it would need to have resolved to a non-null MouseCursor which we can then wrap with WidgetStateProperty.all. If the defaultMouseCursor function returns a WidgetStateProperty<MouseCursor>, there would be an extra step to resolve that into a plain non-null MouseCursor which would then be wrapped with WidgetStateProperty.all.

There might be a better way to do all this though that I am missing.

Copy link
Contributor

Choose a reason for hiding this comment

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

If I'm understanding correctly, try this below and then see my other comment about Material Radio using this.

  static WidgetStateProperty<MouseCursor> defaultMouseCursor(Function? onChanged) {
    final MouseCursor mouseCursor = (onChanged != null && kIsWeb)
      ? SystemMouseCursors.click
      : SystemMouseCursors.basic;
    return WidgetStateProperty.all<MouseCursor>(mouseCursor);
  }

@@ -297,7 293,7 @@ class _CupertinoRadioState<T> extends State<CupertinoRadio<T>> with TickerProvid
checked: widget._selected,
selected: accessibilitySelected,
child: buildToggleable(
mouseCursor: effectiveMouseCursor,
mouseCursor: widget.mouseCursor ?? WidgetStateProperty.all(CupertinoRadio.defaultMouseCursor(widget.onChanged)),
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of doing this here, can you set the default in the parameter list of the constructor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

defaultMouseCursor takes widget.onChanged as an argument. Since widget.onChanged is non-const, defaultMouseCursor can't be set as the default mouseCursor in the parameter list.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah it's a const constructor. Sounds good as-is then.

Comment on lines 450 to 451
mouseCursor: WidgetStateProperty.all(widget.mouseCursor
?? CupertinoRadio.defaultMouseCursor(widget.onChanged)),
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, can you do this in the constructor parameter list?

Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

Some ideas about how to make defaultMouseCursor be a WidgetStateProperty, but LGTM 👍 either way.

@@ -297,7 293,7 @@ class _CupertinoRadioState<T> extends State<CupertinoRadio<T>> with TickerProvid
checked: widget._selected,
selected: accessibilitySelected,
child: buildToggleable(
mouseCursor: effectiveMouseCursor,
mouseCursor: widget.mouseCursor ?? WidgetStateProperty.all(CupertinoRadio.defaultMouseCursor(widget.onChanged)),
Copy link
Contributor

Choose a reason for hiding this comment

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

Ah it's a const constructor. Sounds good as-is then.

Comment on lines 450 to 453
mouseCursor: WidgetStateProperty.resolveWith((Set<MaterialState> states) {
return MaterialStateProperty.resolveAs<MouseCursor?>(widget.mouseCursor, states)
?? CupertinoRadio.defaultMouseCursor(widget.onChanged);
}),
Copy link
Contributor

Choose a reason for hiding this comment

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

If CupertinoRadio.defaultMouseCursor returns a WidgetStateProperty then could you do this instead?

              mouseCursor: widget.mouseCursor == null
                ? CupertinoRadio.defaultMouseCursor(widget.onChanged)
                : WidgetStateProperty.all<MouseCursor>(widget.mouseCursor!),

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This works, I forgot we could just use ! to keep the analyzer quiet. Thanks for the insight!

@@ -210,6 208,13 @@ class CupertinoRadio<T> extends StatefulWidget {

bool get _selected => value == groupValue;

/// The default mouse cursor of a [CupertinoRadio].
static MouseCursor defaultMouseCursor(Function? onChanged) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If I'm understanding correctly, try this below and then see my other comment about Material Radio using this.

  static WidgetStateProperty<MouseCursor> defaultMouseCursor(Function? onChanged) {
    final MouseCursor mouseCursor = (onChanged != null && kIsWeb)
      ? SystemMouseCursors.click
      : SystemMouseCursors.basic;
    return WidgetStateProperty.all<MouseCursor>(mouseCursor);
  }

@victorsanni victorsanni added the autosubmit Merge PR when tree becomes green via auto submit App label Jul 19, 2024
@auto-submit auto-submit bot merged commit 5ef969a into flutter:master Jul 19, 2024
72 checks passed
@victorsanni victorsanni added the cp: beta cherry pick this pull request to beta release candidate branch label Jul 19, 2024
@flutteractionsbot
Copy link

Failed to create CP due to merge conflicts.
You will need to create the PR manually. See the cherrypick wiki for more info.

victorsanni added a commit to victorsanni/flutter that referenced this pull request Jul 19, 2024
…r#151910)

flutter#149681 introduced `mouseCursor `to `CupertinoRadio` as a `MouseCursor` instead of a `WidgetStateProperty` to match Material Radio's `mouseCursor` property for `.adaptive`.

This PR changes `mouseCursor` to be of type `WidgetStateProperty<MouseCursor>` as per review comments in flutter#151788 (comment).

PR bringing `mouseCursor` into `CupertinoRadio`: flutter#149681.

Part of flutter#58192
victorsanni added a commit to victorsanni/flutter that referenced this pull request Jul 19, 2024
…r#151910)

flutter#149681 introduced `mouseCursor `to `CupertinoRadio` as a `MouseCursor` instead of a `WidgetStateProperty` to match Material Radio's `mouseCursor` property for `.adaptive`.

This PR changes `mouseCursor` to be of type `WidgetStateProperty<MouseCursor>` as per review comments in flutter#151788 (comment).

PR bringing `mouseCursor` into `CupertinoRadio`: flutter#149681.

Part of flutter#58192
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 24, 2024
@victorsanni
Copy link
Contributor Author

@Piinks should this PR be reverted until final discussions on WidgetStateProperty? Or should the mouseCursor property be removed entirely (and then cherrypick that removal into beta)?

@Piinks
Copy link
Contributor

Piinks commented Jul 24, 2024

Let's revert this, and leave the mouseCursor property that made into beta as is. 👍

@victorsanni victorsanni added the revert Autorevert PR (with "Reason for revert:" comment) label Jul 24, 2024
Copy link
Contributor

auto-submit bot commented Jul 24, 2024

Time to revert pull request flutter/flutter/151910 has elapsed.
You need to open the revert manually and process as a regular pull request.

@auto-submit auto-submit bot removed the revert Autorevert PR (with "Reason for revert:" comment) label Jul 24, 2024
@victorsanni
Copy link
Contributor Author

Reason for revert: Needs further discussion on the pros and cons of adding new properties as WidgetStateProperty

@victorsanni victorsanni added the revert Autorevert PR (with "Reason for revert:" comment) label Jul 24, 2024
Copy link
Contributor

auto-submit bot commented Jul 24, 2024

Time to revert pull request flutter/flutter/151910 has elapsed.
You need to open the revert manually and process as a regular pull request.

@auto-submit auto-submit bot removed the revert Autorevert PR (with "Reason for revert:" comment) label Jul 24, 2024
victorsanni added a commit that referenced this pull request Jul 24, 2024
auto-submit bot pushed a commit that referenced this pull request Jul 24, 2024
#152254)

Reverts #151910, awaiting further discussion on `WidgetStateProperty`.
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 25, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 25, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 25, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 25, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 25, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 26, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 26, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 26, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 26, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 27, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 27, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 28, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Jul 28, 2024
TytaniumDev pushed a commit to TytaniumDev/flutter that referenced this pull request Aug 7, 2024
…r#151910)

flutter#149681 introduced `mouseCursor `to `CupertinoRadio` as a `MouseCursor` instead of a `WidgetStateProperty` to match Material Radio's `mouseCursor` property for `.adaptive`.

This PR changes `mouseCursor` to be of type `WidgetStateProperty<MouseCursor>` as per review comments in flutter#151788 (comment).

PR bringing `mouseCursor` into `CupertinoRadio`: flutter#149681.

Part of flutter#58192
TytaniumDev pushed a commit to TytaniumDev/flutter that referenced this pull request Aug 7, 2024
flutter#152254)

Reverts flutter#151910, awaiting further discussion on `WidgetStateProperty`.
Buchimi pushed a commit to Buchimi/flutter that referenced this pull request Sep 2, 2024
…r#151910)

flutter#149681 introduced `mouseCursor `to `CupertinoRadio` as a `MouseCursor` instead of a `WidgetStateProperty` to match Material Radio's `mouseCursor` property for `.adaptive`.

This PR changes `mouseCursor` to be of type `WidgetStateProperty<MouseCursor>` as per review comments in flutter#151788 (comment).

PR bringing `mouseCursor` into `CupertinoRadio`: flutter#149681.

Part of flutter#58192
Buchimi pushed a commit to Buchimi/flutter that referenced this pull request Sep 2, 2024
flutter#152254)

Reverts flutter#151910, awaiting further discussion on `WidgetStateProperty`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App cp: beta cherry pick this pull request to beta release candidate branch f: cupertino flutter/packages/flutter/cupertino repository f: material design flutter/packages/flutter/material 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