-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Feat: Add fillColor property for cupertinoCheckbox #151761
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
Feat: Add fillColor property for cupertinoCheckbox #151761
Conversation
6f0bd12 to
76f7d45
Compare
76f7d45 to
2e2d409
Compare
2e2d409 to
9d0d231
Compare
ba765f9 to
27cb3ea
Compare
nate-thegrate
left a comment
There was a problem hiding this 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!
bc980d6 to
3aa9557
Compare
f86fb74 to
9d9c05f
Compare
victorsanni
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a PR out making some of these changes, feel free to take inspiration from it (for tests, documentation, and such): https://github.com/flutter/flutter/pull/148804/files#diff-6c819d3ed61b4436b70dc3d4cbeac15e24bc3705d0c3acf7761e58bcece5cf29
| /// | ||
| /// 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /// the disabled state, [CupertinoColors.activeBlue] is used in the | |
| /// the disabled state, and [CupertinoColors.activeBlue] is used in the |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
- fillColor
- activeColor
- CupertinoColors.activeBlue
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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:
flutter/packages/flutter/lib/src/material/switch.dart
Lines 936 to 940 in 7d5c1c0
| 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)!; |
b60e510 to
8407d85
Compare
|
@victorsanni I have done suggested changes. |
37e4267 to
953eec9
Compare
| /// 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /// 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.
| /// 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. |
There was a problem hiding this comment.
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:
| /// 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /// state, it will be used instead of this color. | |
| /// state, [fillColor] will be used instead of [inactiveColor]. |
| final Set<WidgetState> activeStates = states..add(WidgetState.selected); | ||
| final Set<WidgetState> inactiveStates = states..remove(WidgetState.selected); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| final Color activeColor = widget.activeColor ?? CupertinoColors.activeBlue; | ||
| final Color effectiveActiveColor = widget.fillColor?.resolve(activeStates) ?? activeColor; |
There was a problem hiding this comment.
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?
| 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.
daa7fe4 to
dd4ff0d
Compare
dd4ff0d to
5e934a1
Compare
victorsanni
left a comment
There was a problem hiding this 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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
| ?? _defaultFillColor.resolve(activeStates); | |
| ?? _defaultFillColor.resolve(activeStates); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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;
dkwingsmt
left a comment
There was a problem hiding this 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
98c4014 to
6ee062a
Compare
6ee062a to
9101036
Compare
|
@victorsanni and @dkwingsmt, I have made required changes. Can you please review ? |
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
Feat: Add `fillColor` property for `CupertinoCheckbox` Required for flutter#151252
Feat: Add `fillColor` property for `CupertinoCheckbox` Required for flutter#151252
Feat: Add
fillColorproperty forCupertinoCheckboxRequired for #151252
Pre-launch Checklist
///).