-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Make Checkbox adaptive without delegating to CupertinoCheckbox
#147892
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
Conversation
Piinks
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 think it was mentioned offline that one of the benefits here was that the CupertinoCheckbox did not implement an animation that could now be reflected here by re-implementing it in material.
Can you share some images or screen recordings to the PR description that show the difference between the original material Checkbox, the original CupertinoCheckbox, and the new adaptive cupertino checkbox this PR creates to illustrate the differences?
| ..color = checkColor | ||
| ..style = PaintingStyle.stroke | ||
| ..strokeWidth = _kStrokeWidth; | ||
| ..strokeWidth = _isCupertino |
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.
Feel like _isCupertino is not necessary if we already have the enum. Can we do something like this?
..StrokeWidth = switch (designSpec) {
_DesignSpec.cupertino => _kCupertinoStrokeWidth,
_DesignSpec.material => _kStrokeWidth,
}
Here and all the if (_isCupertino) statements below:)
|
Somehow this PR doesn't trigger "Google testing", maybe mark this to be Ready to review? I think this PR change probably will break G3 and we might also need to add the |
| ? _CheckboxDefaultsM3(context) | ||
| : _CheckboxDefaultsM2(context); | ||
| final CheckboxThemeData defaults; | ||
| switch (widget._checkboxType) { |
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.
Can we look and see if there is a way to reduce the number of switch statements? I am trying to consolidate Switch down to only have one platform switch statement, so the code is less complex.
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.
Done.
**NOTE: Previous [PR](#148804) was closed because of a bad merge leading to pollution with unrelated commits.** This PR improves on the look and feel of `CupertinoCheckbox` to more closely match native iOS/macOS checkboxes. Adds the following updates from a native macOS checkbox: * Fill color of an unchecked checkbox is a linear gradient that goes from darker at the top to lighter at the bottom in dark mode * Size of box reduced from 18.0 to 14.0 * Stroke width of check reduced from 2.5 to 2.0 * Border color changed from solid black to gray black in light mode and a transparent gray in dark mode * In light mode, checkbox darkens when pressed * In dark mode, checkbox lightens when pressed * Default blue color of a checked checkbox is darker in dark mode ### Light Mode | Native macOS | Flutter Before | Flutter After | | ----------- | ----------- | ----------- | | <img width="63" alt="native checkbox" src="https://github.com/flutter/flutter/assets/77553258/d57d4c78-2e67-49fb-9491-a5acee3782a7"> | <img width="66" alt="Screenshot 2024-06-27 at 10 23 18 AM" src="https://github.com/flutter/flutter/assets/77553258/31c913ff-d36f-4eb5-b737-3a9117bd7eff"> | <img width="66" alt="Screenshot 2024-06-27 at 10 39 22 AM" src="https://github.com/flutter/flutter/assets/77553258/ace8ef29-efae-4049-8f78-13fd39851947"> | ### Dark Mode - Checked | Native macOS | Flutter Before | Flutter After | | ----------- | ----------- | ----------- | | <img width="22" alt="native light" src="https://github.com/user-attachments/assets/fc52d5e1-7ab0-4a5d-b0fa-5b5bee3ed39d"> | <img width="22" alt="flutter before light" src="https://github.com/user-attachments/assets/16e033a1-d2dd-4fb2-a5a5-f730c5f7cdc7"> | <img width="22" alt="flutter after light" src="https://github.com/user-attachments/assets/8c0cff99-930e-4f5e-8540-e64294c1b4fa"> | ### Dark Mode - Unchecked | Native macOS | Flutter Before | Flutter After | | ----------- | ----------- | ----------- | | <img width="22" alt="native dark mode" src="https://github.com/user-attachments/assets/333280a0-85db-4464-9663-03ef7eafc270"> | <img width="22" alt="flutter before dark mode" src="https://github.com/user-attachments/assets/a46e01ec-0d0b-4bb7-8d08-4b2723424a12"> | <img width="22" alt="flutter dark mode" src="https://github.com/user-attachments/assets/a70ae4ad-f1ad-4441-a416-350cbdc32679"> | ### Light Mode - Disabled | Native macOS | Flutter Before | Flutter After | | --- | --- | --- | | <img width="121" alt="native disabled checkbox" src="https://github.com/user-attachments/assets/ed050d14-efec-49dd-82b6-1e7ed7fa99f9"> | <img width="136" alt="flutter b4 disabled checkbox" src="https://github.com/user-attachments/assets/564918cf-f936-448d-b975-7bf9248bbf35"> | <img width="156" alt="flutter disabled checkbox" src="https://github.com/user-attachments/assets/82f672a7-12e8-469c-99af-9f94c959df8f"> | ### Dark Mode - Disabled | Native macOS | Flutter Before | Flutter After | | --- | --- | --- | | <img width="110" alt="disabled dark checkbox native" src="https://github.com/user-attachments/assets/02a43b3f-5619-4b05-9066-2fd43a58c956"> | <img width="136" alt="disabled dark checkbox flutter b4" src="https://github.com/user-attachments/assets/3a3db322-2002-4808-adc0-b10a7ab42381"> | <img width="140" alt="disabled dark checkbox flutter" src="https://github.com/user-attachments/assets/cb91955a-8302-4dc7-8050-221fa2a7045f"> Fixes #148719. Related PR exploring these changes: #147892 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [test-exempt]: https://github.com/flutter/flutter/wiki/Tree-hygiene#tests [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [Features we expect every widget to implement]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat [Data Driven Fixes]: https://github.com/flutter/flutter/wiki/Data-driven-Fixes --------- Co-authored-by: Kate Lovett <[email protected]>
**NOTE: Previous [PR](flutter#148804) was closed because of a bad merge leading to pollution with unrelated commits.** This PR improves on the look and feel of `CupertinoCheckbox` to more closely match native iOS/macOS checkboxes. Adds the following updates from a native macOS checkbox: * Fill color of an unchecked checkbox is a linear gradient that goes from darker at the top to lighter at the bottom in dark mode * Size of box reduced from 18.0 to 14.0 * Stroke width of check reduced from 2.5 to 2.0 * Border color changed from solid black to gray black in light mode and a transparent gray in dark mode * In light mode, checkbox darkens when pressed * In dark mode, checkbox lightens when pressed * Default blue color of a checked checkbox is darker in dark mode ### Light Mode | Native macOS | Flutter Before | Flutter After | | ----------- | ----------- | ----------- | | <img width="63" alt="native checkbox" src="https://github.com/flutter/flutter/assets/77553258/d57d4c78-2e67-49fb-9491-a5acee3782a7"> | <img width="66" alt="Screenshot 2024-06-27 at 10 23 18 AM" src="https://github.com/flutter/flutter/assets/77553258/31c913ff-d36f-4eb5-b737-3a9117bd7eff"> | <img width="66" alt="Screenshot 2024-06-27 at 10 39 22 AM" src="https://github.com/flutter/flutter/assets/77553258/ace8ef29-efae-4049-8f78-13fd39851947"> | ### Dark Mode - Checked | Native macOS | Flutter Before | Flutter After | | ----------- | ----------- | ----------- | | <img width="22" alt="native light" src="https://github.com/user-attachments/assets/fc52d5e1-7ab0-4a5d-b0fa-5b5bee3ed39d"> | <img width="22" alt="flutter before light" src="https://github.com/user-attachments/assets/16e033a1-d2dd-4fb2-a5a5-f730c5f7cdc7"> | <img width="22" alt="flutter after light" src="https://github.com/user-attachments/assets/8c0cff99-930e-4f5e-8540-e64294c1b4fa"> | ### Dark Mode - Unchecked | Native macOS | Flutter Before | Flutter After | | ----------- | ----------- | ----------- | | <img width="22" alt="native dark mode" src="https://github.com/user-attachments/assets/333280a0-85db-4464-9663-03ef7eafc270"> | <img width="22" alt="flutter before dark mode" src="https://github.com/user-attachments/assets/a46e01ec-0d0b-4bb7-8d08-4b2723424a12"> | <img width="22" alt="flutter dark mode" src="https://github.com/user-attachments/assets/a70ae4ad-f1ad-4441-a416-350cbdc32679"> | ### Light Mode - Disabled | Native macOS | Flutter Before | Flutter After | | --- | --- | --- | | <img width="121" alt="native disabled checkbox" src="https://github.com/user-attachments/assets/ed050d14-efec-49dd-82b6-1e7ed7fa99f9"> | <img width="136" alt="flutter b4 disabled checkbox" src="https://github.com/user-attachments/assets/564918cf-f936-448d-b975-7bf9248bbf35"> | <img width="156" alt="flutter disabled checkbox" src="https://github.com/user-attachments/assets/82f672a7-12e8-469c-99af-9f94c959df8f"> | ### Dark Mode - Disabled | Native macOS | Flutter Before | Flutter After | | --- | --- | --- | | <img width="110" alt="disabled dark checkbox native" src="https://github.com/user-attachments/assets/02a43b3f-5619-4b05-9066-2fd43a58c956"> | <img width="136" alt="disabled dark checkbox flutter b4" src="https://github.com/user-attachments/assets/3a3db322-2002-4808-adc0-b10a7ab42381"> | <img width="140" alt="disabled dark checkbox flutter" src="https://github.com/user-attachments/assets/cb91955a-8302-4dc7-8050-221fa2a7045f"> Fixes flutter#148719. Related PR exploring these changes: flutter#147892 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [test-exempt]: https://github.com/flutter/flutter/wiki/Tree-hygiene#tests [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [Features we expect every widget to implement]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat [Data Driven Fixes]: https://github.com/flutter/flutter/wiki/Data-driven-Fixes --------- Co-authored-by: Kate Lovett <[email protected]>
**NOTE: Previous [PR](flutter#148804) was closed because of a bad merge leading to pollution with unrelated commits.** This PR improves on the look and feel of `CupertinoCheckbox` to more closely match native iOS/macOS checkboxes. Adds the following updates from a native macOS checkbox: * Fill color of an unchecked checkbox is a linear gradient that goes from darker at the top to lighter at the bottom in dark mode * Size of box reduced from 18.0 to 14.0 * Stroke width of check reduced from 2.5 to 2.0 * Border color changed from solid black to gray black in light mode and a transparent gray in dark mode * In light mode, checkbox darkens when pressed * In dark mode, checkbox lightens when pressed * Default blue color of a checked checkbox is darker in dark mode ### Light Mode | Native macOS | Flutter Before | Flutter After | | ----------- | ----------- | ----------- | | <img width="63" alt="native checkbox" src="https://github.com/flutter/flutter/assets/77553258/d57d4c78-2e67-49fb-9491-a5acee3782a7"> | <img width="66" alt="Screenshot 2024-06-27 at 10 23 18 AM" src="https://github.com/flutter/flutter/assets/77553258/31c913ff-d36f-4eb5-b737-3a9117bd7eff"> | <img width="66" alt="Screenshot 2024-06-27 at 10 39 22 AM" src="https://github.com/flutter/flutter/assets/77553258/ace8ef29-efae-4049-8f78-13fd39851947"> | ### Dark Mode - Checked | Native macOS | Flutter Before | Flutter After | | ----------- | ----------- | ----------- | | <img width="22" alt="native light" src="https://github.com/user-attachments/assets/fc52d5e1-7ab0-4a5d-b0fa-5b5bee3ed39d"> | <img width="22" alt="flutter before light" src="https://github.com/user-attachments/assets/16e033a1-d2dd-4fb2-a5a5-f730c5f7cdc7"> | <img width="22" alt="flutter after light" src="https://github.com/user-attachments/assets/8c0cff99-930e-4f5e-8540-e64294c1b4fa"> | ### Dark Mode - Unchecked | Native macOS | Flutter Before | Flutter After | | ----------- | ----------- | ----------- | | <img width="22" alt="native dark mode" src="https://github.com/user-attachments/assets/333280a0-85db-4464-9663-03ef7eafc270"> | <img width="22" alt="flutter before dark mode" src="https://github.com/user-attachments/assets/a46e01ec-0d0b-4bb7-8d08-4b2723424a12"> | <img width="22" alt="flutter dark mode" src="https://github.com/user-attachments/assets/a70ae4ad-f1ad-4441-a416-350cbdc32679"> | ### Light Mode - Disabled | Native macOS | Flutter Before | Flutter After | | --- | --- | --- | | <img width="121" alt="native disabled checkbox" src="https://github.com/user-attachments/assets/ed050d14-efec-49dd-82b6-1e7ed7fa99f9"> | <img width="136" alt="flutter b4 disabled checkbox" src="https://github.com/user-attachments/assets/564918cf-f936-448d-b975-7bf9248bbf35"> | <img width="156" alt="flutter disabled checkbox" src="https://github.com/user-attachments/assets/82f672a7-12e8-469c-99af-9f94c959df8f"> | ### Dark Mode - Disabled | Native macOS | Flutter Before | Flutter After | | --- | --- | --- | | <img width="110" alt="disabled dark checkbox native" src="https://github.com/user-attachments/assets/02a43b3f-5619-4b05-9066-2fd43a58c956"> | <img width="136" alt="disabled dark checkbox flutter b4" src="https://github.com/user-attachments/assets/3a3db322-2002-4808-adc0-b10a7ab42381"> | <img width="140" alt="disabled dark checkbox flutter" src="https://github.com/user-attachments/assets/cb91955a-8302-4dc7-8050-221fa2a7045f"> Fixes flutter#148719. Related PR exploring these changes: flutter#147892 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [test-exempt]: https://github.com/flutter/flutter/wiki/Tree-hygiene#tests [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [Features we expect every widget to implement]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat [Data Driven Fixes]: https://github.com/flutter/flutter/wiki/Data-driven-Fixes --------- Co-authored-by: Kate Lovett <[email protected]>
Currently,
Checkbox.adaptivedelegates toCupertinoCheckboxwhen the current platform isiOSormacOS. This PR serves to make MaterialCheckboxconfigure to a Cupertino look and feel when theCheckbox.adaptiveconstructor is used oniOSormacOS.Currently, delegating to
CupertinoCheckboxmeans that many parameters to materialCheckboxare ignored:flutter/packages/flutter/lib/src/material/checkbox.dart
Lines 109 to 115 in 54e6646
This PR allows for an adaptive checkbox that keeps all the parameters to the regular material
Checkbox, allowing for the same levels of customization, thus fixing issues like #134917.#134917 (comment) provides the value proposal behind this PR.
Before:

After:

code sample
Related PR: #130425
Pre-launch Checklist
///).