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

Migrated Checkbox to Material 3 Colors #110537

Merged
merged 7 commits into from Aug 31, 2022

Conversation

QuncCccccc
Copy link
Contributor

@QuncCccccc QuncCccccc commented Aug 29, 2022

Updated checkbox colors so they use the material 3 palette.

Screen Shot 2022-08-29 at 1 44 31 PMScreen Shot 2022-08-29 at 1 46 20 PM

In order to use the Checkbox with the new Material 3 defaults, turn on the useMaterial3 flag in the ThemeData:

  return MaterialApp(
    theme: ThemeData(useMaterial3: true),
    // ...
  );

#104446

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].
  • All existing and new tests are passing.

@flutter-dashboard flutter-dashboard bot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. team Infra upgrades, team productivity, code health, technical debt. See also team: labels. labels Aug 29, 2022
@QuncCccccc QuncCccccc marked this pull request as ready for review August 29, 2022 22:33
Copy link
Contributor

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

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

It seems possible that the implementation of this widget could be made substantially simpler in a future PR. Perhaps the code that computes "effective" colors by adding a state to the widgets actual state, could be deferred. So that the painter only computed those colors when it needed them. The division of labor between the Toggleable classes and this class seems like more overhead than should be needed.

if (states.contains(MaterialState.pressed)) {
return ${componentColor('md.comp.checkbox.unselected.pressed.state-layer')};
}
return null;
Copy link
Contributor

Choose a reason for hiding this comment

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

CC @darrenaustin
Should this be Colors.transparent?

?? checkboxTheme.fillColor?.resolve(inactiveStates)
?? _defaultFillColor.resolve(inactiveStates);
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.

two-space indent here and below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

if (states.contains(MaterialState.hovered)) {
return ${componentColor('md.comp.checkbox.selected.hover.container')};
}
if (states.contains(MaterialState.pressed)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the pressed test come first (here and elsewhere)? When pressed becomes true, hovered will also always be true, and so we'll miss this if statement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Thanks for catching this!

Copy link
Member

@guidezpl guidezpl left a comment

Choose a reason for hiding this comment

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

A couple of TODOs

  • CheckboxThemeData.side needs to support MaterialStateProperty<Side> instead of Side
  • Error states

Are you planning on addressing these in this PR or a future one?

packages/flutter/lib/src/material/checkbox.dart Outdated Show resolved Hide resolved
Copy link
Member

@guidezpl guidezpl left a comment

Choose a reason for hiding this comment

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

One more thing, the useMaterial3 documentation should be updated

@QuncCccccc
Copy link
Contributor Author

A couple of TODOs

  • CheckboxThemeData.side needs to support MaterialStateProperty<Side> instead of Side
  • Error states

Are you planning on addressing these in this PR or a future one?

I will create a separate PR for the TODOs:) Thanks!

Copy link
Contributor

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

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

LGTM

return _colors.onSurface.withOpacity(0.38);
}
if (states.contains(MaterialState.selected)) {
if (states.contains(MaterialState.pressed)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

TODO (future PR): update the code generator to collapse code like this.

packages/flutter/lib/src/material/checkbox.dart Outdated Show resolved Hide resolved
Copy link
Member

@guidezpl guidezpl left a comment

Choose a reason for hiding this comment

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

Edited the description to not close the issue, pending the remaining work.

@QuncCccccc QuncCccccc changed the title Migrated Checkbox to Material 3 Migrated Checkbox to Material 3 Colors Aug 31, 2022
@QuncCccccc QuncCccccc added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 31, 2022
@auto-submit auto-submit bot merged commit a490a6a into flutter:master Aug 31, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Sep 1, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Sep 1, 2022
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: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. team Infra upgrades, team productivity, code health, technical debt. See also team: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants