Skip to content

Conversation

@rkishan516
Copy link
Contributor

Feat: Add fillColor property for CupertinoCheckbox

Required for #151252

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 this PR is [test-exempt].
  • I followed the [breaking change policy] and added [Data Driven Fixes] where supported.
  • All existing and new tests are passing.

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: cupertino flutter/packages/flutter/cupertino repository labels Jul 15, 2024
@rkishan516 rkishan516 force-pushed the remove-inactive-color-from-cupertino-checkbox branch from 6f0bd12 to 76f7d45 Compare July 15, 2024 15:44
@github-actions github-actions bot added d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos c: tech-debt Technical debt, code quality, testing, etc. labels Jul 15, 2024
@rkishan516 rkishan516 force-pushed the remove-inactive-color-from-cupertino-checkbox branch from 76f7d45 to 2e2d409 Compare July 15, 2024 15:46
@github-actions github-actions bot removed d: api docs Issues with https://api.flutter.dev/ d: examples Sample code and demos c: tech-debt Technical debt, code quality, testing, etc. labels Jul 15, 2024
@rkishan516 rkishan516 force-pushed the remove-inactive-color-from-cupertino-checkbox branch from 2e2d409 to 9d0d231 Compare July 15, 2024 15:47
@victorsanni victorsanni requested a review from dkwingsmt July 15, 2024 18:49
@rkishan516 rkishan516 force-pushed the remove-inactive-color-from-cupertino-checkbox branch 5 times, most recently from ba765f9 to 27cb3ea Compare July 18, 2024 10:48
Copy link
Contributor

@nate-thegrate nate-thegrate left a comment

Choose a reason for hiding this comment

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

LGTM with a couple of small nits.

Thanks for adding this!

@rkishan516 rkishan516 force-pushed the remove-inactive-color-from-cupertino-checkbox branch 2 times, most recently from bc980d6 to 3aa9557 Compare July 18, 2024 16:19
@victorsanni victorsanni self-requested a review July 18, 2024 22:16
@rkishan516 rkishan516 force-pushed the remove-inactive-color-from-cupertino-checkbox branch 2 times, most recently from f86fb74 to 9d9c05f Compare July 19, 2024 00:26
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.

///
/// If null, then the value of [activeColor] is used in the selected
/// state. If that is also null, then [CupertinoColors.inactiveGray] is used in
/// the disabled state, [CupertinoColors.activeBlue] is used in the
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// the disabled state, [CupertinoColors.activeBlue] is used in the
/// the disabled state, and [CupertinoColors.activeBlue] is used in the

Copy link
Contributor

Choose a reason for hiding this comment

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

It's confusing that activeColor above also resolves to CupertinoColors.activeBlue. What parameters are prioritized when it comes to setting the color of the checkbox?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If any one is giving null, it resolves to bottom one

  1. fillColor
  2. activeColor
  3. CupertinoColors.activeBlue

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, but that is not clear to someone reading the documentation. The documentation for fillColor and activeColor should both clearly specify this order of precedence.

I'd recommend appending this to activeColor's docs:

  /// If [fillColor] returns a non-null color in the [WidgetState.selected]
  /// state, it will be used instead of this color.

Copy link
Contributor

Choose a reason for hiding this comment

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

Then, since activeColor already defaults to CupertinoColors.activeBlue, fillColor only needs to default to activeColor in the selected state, so that there is a single source of truth for what the final default color is.

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 have updated code to make it simple and in sync with docs. Please review and let me know if it makes more sense now.

final Set<WidgetState> activeStates = states..add(WidgetState.selected);
final Set<WidgetState> inactiveStates = states..remove(WidgetState.selected);

final Color? activeColor = widget.fillColor?.resolve(activeStates) ?? _widgetFillColor.resolve(activeStates);
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be a little confusing to have an activeColor here when the expectation is activeColor should be widget.activeColor. I'd recommend consolidating this activeColor into effectiveActiveColor, so it's clear what all variables are referring to.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are already using effectiveActiveColor, will it be bad if we call it resolvedActiveColor ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reason we are having activeColor and effectiveActiveColor is fillColor and _widgetFillColor might resolve to null.
So, either we can rename activeColor to resolvedActiveColor
or
Just keep effectiveActiveColor that resolves everything

Copy link
Contributor

Choose a reason for hiding this comment

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

Either is fine, but I would prefer the latter because I don't see a need for the extra variable/step, and I can also find that pattern elsewhere in the framework:

final Color effectiveActiveTrackColor = widget.trackColor?.resolve(activeStates)
?? _widgetTrackColor.resolve(activeStates)
?? (applyCupertinoTheme ? cupertinoPrimaryColor : switchTheme.trackColor?.resolve(activeStates))
?? _widgetThumbColor.resolve(activeStates)?.withAlpha(0x80)
?? defaults.trackColor!.resolve(activeStates)!;

@rkishan516 rkishan516 force-pushed the remove-inactive-color-from-cupertino-checkbox branch 4 times, most recently from b60e510 to 8407d85 Compare July 20, 2024 05:07
@rkishan516
Copy link
Contributor Author

@victorsanni I have done suggested changes.

@rkishan516 rkishan516 force-pushed the remove-inactive-color-from-cupertino-checkbox branch from 37e4267 to 953eec9 Compare July 25, 2024 07:26
/// The color to use when this checkbox is checked.
///
/// If [fillColor] returns a non-null color in the [WidgetState.selected]
/// state, it will be used instead of this color.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// state, it will be used instead of this color.
/// state, [fillColor] will be used instead of [activeColor].

I was a little confused at first glance. Maybe this reduces ambiguity a bit.

Comment on lines 162 to 165
/// If null, then the value of [activeColor] is used in the selected
/// state. If that is also null, then [CupertinoColors.inactiveGray] is used in
/// the unselected state, and [CupertinoColors.activeBlue] is used in the
/// selected state.
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest the following way:

Suggested change
/// If null, then the value of [activeColor] is used in the selected
/// state. If that is also null, then [CupertinoColors.inactiveGray] is used in
/// the unselected state, and [CupertinoColors.activeBlue] is used in the
/// selected state.
/// If [fillColor] resolves to null for the requested state, then the fill color falls back to
/// [activeColor] if the state includes [WidgetState.selected], or [inactiveColor] otherwise.

The differences are:

  • It made it clearer on what is null.
  • It removes the duplicate mention of the default values of [activeColor] and [inactiveColor].
  • It is clearer on what is "selected/unselected state".

/// The color used if the checkbox is inactive.
///
/// If [fillColor] returns a non-null color in the unselected
/// state, it will be used instead of this color.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// state, it will be used instead of this color.
/// state, [fillColor] will be used instead of [inactiveColor].

Comment on lines 275 to 364
final Set<WidgetState> activeStates = states..add(WidgetState.selected);
final Set<WidgetState> inactiveStates = states..remove(WidgetState.selected);
Copy link
Contributor

Choose a reason for hiding this comment

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

I thought the other comment mentioned that these lines are changed into using union and difference. But they're now using ..add and ..remove. Doesn't the current way modify states? For example, if the current state has WidgetState.selected, won't state become unselected after the build?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is true. I wonder why this has not caused problems in Material Checkbox though, because it does seem bad.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, this is what I don't like about ToggleableStateMixin: it has a states getter that re-constructs a Set each time it's accessed.

So the above code works fine, but it gives the appearance that activeStates and inactiveStates are modifying the same object.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah I see. Yeah... the naming is bad here.

Copy link
Contributor

@dkwingsmt dkwingsmt Jul 25, 2024

Choose a reason for hiding this comment

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

Maybe add a comment:

// The `states` getter constructs a new set every time, which is therefore safe to edit in place.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, although we should do it in a separate PR since it's potentially breaking.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

    final Set<WidgetState> selectedState = <WidgetState>{WidgetState.selected};
    final Set<WidgetState> activeStates = states.union(selectedState);
    final Set<WidgetState> inactiveStates = states.difference(selectedState);

How does this looks like, clean and easy to understand.

Copy link
Contributor

@nate-thegrate nate-thegrate Jul 26, 2024

Choose a reason for hiding this comment

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

That'd be good, but my guess is that .union() and .difference() introduce a small performance penalty when compared with .add() and .remove().

If we end up going this route, then const Set<WidgetState> selectedState would be ideal.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I think the current way is ok as long as it's commented.

Copy link
Contributor Author

@rkishan516 rkishan516 Jul 27, 2024

Choose a reason for hiding this comment

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

// The `states` getter constructs a new set every time, which is therefore safe to edit in place.

Okay, I have added this comment.

Comment on lines 278 to 279
final Color activeColor = widget.activeColor ?? CupertinoColors.activeBlue;
final Color effectiveActiveColor = widget.fillColor?.resolve(activeStates) ?? activeColor;
Copy link
Contributor

Choose a reason for hiding this comment

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

Shall we combine the two lines?

Suggested change
final Color activeColor = widget.activeColor ?? CupertinoColors.activeBlue;
final Color effectiveActiveColor = widget.fillColor?.resolve(activeStates) ?? activeColor;
final Color activeColor = widget.fillColor?.resolve(activeStates)
?? widget.activeColor
?? CupertinoColors.activeBlue;

Also for the inactive color below.

@rkishan516 rkishan516 force-pushed the remove-inactive-color-from-cupertino-checkbox branch 3 times, most recently from daa7fe4 to dd4ff0d Compare July 27, 2024 02:05
@rkishan516 rkishan516 force-pushed the remove-inactive-color-from-cupertino-checkbox branch from dd4ff0d to 5e934a1 Compare August 2, 2024 02:34
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.

This PR is getting closer to merging, thanks for your patience!


final Color effectiveActiveColor = _defaultFillColor.resolve(activeStates);
final Color effectiveActiveColor = widget.fillColor?.resolve(activeStates)
?? _defaultFillColor.resolve(activeStates);
Copy link
Contributor

Choose a reason for hiding this comment

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

The indentation here feels weird, does this follow the style guide?

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if the style guide has an enforcing rule but usually we use 2 spaces or 4 spaces in this kind of cases.

Suggested change
?? _defaultFillColor.resolve(activeStates);
?? _defaultFillColor.resolve(activeStates);

Copy link
Contributor

Choose a reason for hiding this comment

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

True. All the indentation stipulations in the style guide seem to suggest two spaces.

Copy link
Contributor

@dkwingsmt dkwingsmt Aug 5, 2024

Choose a reason for hiding this comment

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

Not really. For example, https://github.com/flutter/flutter/blob/master/docs/contributing/Style-guide-for-Flutter-repo.md#prefer-a-maximum-line-length-of-80-characters provided an example of

final int c =
    a.very.very....

Although it's in the BAD example section, it still shows that if we want a new line, the new line can use 4 spaces. I don't think this is really something that we really enforce.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also in https://github.com/flutter/flutter/blob/master/docs/contributing/Style-guide-for-Flutter-repo.md#align-expressions there is an example that shows what happens if we want to indent at the middle of an expression:

// BAD:
return foo.x == x &&
    foo.y == y &&
    foo.z == z;

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 after addressing current comments

@rkishan516 rkishan516 force-pushed the remove-inactive-color-from-cupertino-checkbox branch 2 times, most recently from 98c4014 to 6ee062a Compare August 5, 2024 23:17
@rkishan516 rkishan516 force-pushed the remove-inactive-color-from-cupertino-checkbox branch from 6ee062a to 9101036 Compare August 5, 2024 23:20
@rkishan516
Copy link
Contributor Author

@victorsanni and @dkwingsmt, I have made required changes. Can you please review ?

@victorsanni victorsanni added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 6, 2024
@auto-submit auto-submit bot merged commit a9b2d8d into flutter:master Aug 6, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 6, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 6, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Aug 7, 2024
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Aug 7, 2024
Manual roll requested by [email protected]

flutter/flutter@1dd7141...0a7f8af

2024-08-06 [email protected] Support clearing selection programmatically through SelectableRegionState (flutter/flutter#152882)
2024-08-06 [email protected] Roll Flutter Engine from aabd582e9c7e to 206e86ee8a40 (4 revisions) (flutter/flutter#152962)
2024-08-06 49699333+dependabot[bot]@users.noreply.github.com Bump actions/upload-artifact from 4.3.4 to 4.3.6 (flutter/flutter#152964)
2024-08-06 49699333+dependabot[bot]@users.noreply.github.com Bump github/codeql-action from 3.25.15 to 3.26.0 (flutter/flutter#152965)
2024-08-06 [email protected] [tool] Guard process writes to frontend server in `ResidentCompiler` (flutter/flutter#152358)
2024-08-06 [email protected] Fix Linux_android_emu tests late initialization errors (flutter/flutter#152932)
2024-08-06 [email protected] Marks Mac integration_ui_test_test_macos to be flaky (flutter/flutter#152213)
2024-08-06 [email protected] Roll pub packages (flutter/flutter#152956)
2024-08-06 [email protected] [API Examples] `scroll_direction.0_test.dart` & `growth_direction.0_test.dart` (flutter/flutter#152941)
2024-08-06 [email protected] [devicelab] opt gallery benchmarks and platform view test into merged thread mode. (flutter/flutter#152940)
2024-08-06 [email protected] Roll Flutter Engine from e97955bf12ac to aabd582e9c7e (1 revision) (flutter/flutter#152948)
2024-08-06 [email protected] Roll pub packages (flutter/flutter#152945)
2024-08-06 [email protected] [material/menu_anchor.dart] MenuAnchor focus refactoring for RawMenuAnchor (flutter/flutter#150950)
2024-08-06 [email protected] Roll Flutter Engine from 99da2cab3f6d to e97955bf12ac (2 revisions) (flutter/flutter#152944)
2024-08-06 [email protected] fix: add parameter to maintainState of SearchDelegate (flutter/flutter#152444)
2024-08-06 [email protected] Feat: Add fillColor property for cupertinoCheckbox (flutter/flutter#151761)
2024-08-06 [email protected] Slider does not show changed label value for keyboard users fix (flutter/flutter#152886)
2024-08-06 [email protected] Add Nate Wilson to authors (flutter/flutter#152907)
2024-08-06 [email protected] Roll Flutter Engine from 7fc38bef4775 to 99da2cab3f6d (1 revision) (flutter/flutter#152934)
2024-08-06 [email protected] Roll Packages from 82e8d1e to 551bde5 (12 revisions) (flutter/flutter#152930)
2024-08-06 [email protected] Roll Flutter Engine from 84116159ebfc to 7fc38bef4775 (1 revision) (flutter/flutter#152924)
2024-08-06 [email protected] Roll Flutter Engine from f75ffb65cfe3 to 84116159ebfc (1 revision) (flutter/flutter#152917)
2024-08-06 [email protected] Roll Flutter Engine from f5f6e966e7e7 to f75ffb65cfe3 (2 revisions) (flutter/flutter#152915)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
TytaniumDev pushed a commit to TytaniumDev/flutter that referenced this pull request Aug 7, 2024
Feat: Add `fillColor` property for `CupertinoCheckbox`

Required for flutter#151252
Buchimi pushed a commit to Buchimi/flutter that referenced this pull request Sep 2, 2024
Feat: Add `fillColor` property for `CupertinoCheckbox`

Required for flutter#151252
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 11, 2024
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 12, 2024
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 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