Skip to content

Conversation

@LongCatIsLooong
Copy link
Contributor

@LongCatIsLooong LongCatIsLooong commented Sep 5, 2019

Description

  • Changing the default background color of CupertinoDatePicker and CupertinoTimerPicker to null, which disables background painting entirely (i.e. the picker is going to have a completely transparent background), to match the native UIPicker and UIDatePicker.
  • Add dark mode support.
  • Disable the gradient painting when the background is null, because it looks really bad when the background is dark and backgroundColor = null

Golden Changes

https://github.com/flutter/goldens/pull/43/files?short_path=0bfad5e#diff-0bfad5e92f7d3a6380af2f64b62d3cf2

Related Issues

#35541
Mitigates #39685
TODO: #16831

Screenshots over black background, with backgroundColor = null.

The font color is set to blue so it's visible in both screenshots.

old new
Screenshot_1567713620 Screenshot_1568067257

Tests

I added the following tests:

picker dark mode

Fixed goldens.

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require Flutter developers to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (Please read Handling breaking changes). Replace this with a link to the e-mail where you asked for input on this proposed change.
  • No, this is not a breaking change.

@fluttergithubbot fluttergithubbot added f: cupertino flutter/packages/flutter/cupertino repository framework flutter/packages/flutter repository. See also f: labels. labels Sep 5, 2019
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.

LGTM 👍

(widget.backgroundColor.alpha * _kForegroundScreenOpacityFraction).toInt()
Widget _buildMagnifierScreen(Color resolved) {
final Color foreground = resolved?.withAlpha(
(resolved.alpha * _kForegroundScreenOpacityFraction).toInt()
Copy link
Contributor

Choose a reason for hiding this comment

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

Comma at the end here if you have time, I know it was already like that :) Also the identical line below.

@justinmc
Copy link
Contributor

justinmc commented Sep 5, 2019

As we roll out these color changes, is the plan to change default background colors everywhere to transparent if they're white?

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

/// Background color of date picker.
///
/// Defaults to [CupertinoColors.white] when null.
/// Defaults to null, which disables background painting entirely.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please include this detail in the issue's description, explain that we're making the change to improve fidelity wrt native iOS, and include before/after screenshots to help developers understand what's changed.

Copy link
Contributor Author

@LongCatIsLooong LongCatIsLooong Sep 5, 2019

Choose a reason for hiding this comment

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

updated the description

@override
Widget build(BuildContext context) {
Widget result = DefaultTextStyle(
final Color resolvedBackgroundColor = widget.backgroundColor == null
Copy link
Contributor

Choose a reason for hiding this comment

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

If this idiom crops up enough, maybe we should allow CupertinoDyanmicColor.resolve(null, context)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Anything to change now that that PR has been merged?

@LongCatIsLooong
Copy link
Contributor Author

LongCatIsLooong commented Sep 5, 2019

As we roll out these color changes, is the plan to change default background colors everywhere to transparent if they're white?

The main reason the picker is made transparent in this PR is that the native iOS UIPickerView has a transparent background color. I don't think it applies to widgets like CupertinoDialog despite having a white background.

@LongCatIsLooong
Copy link
Contributor Author

@HansMuller @justinmc updated ListWheelScrollView, removed the gradients and replaced it with offCenterOpacity. It's a big change, could you re-review this PR?

@LongCatIsLooong
Copy link
Contributor Author

It includes changes from #33070, in order for the opacity layer to work properly.

@HansMuller
Copy link
Contributor

The new changes look good to me; just had a few small comments.

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.

LGTM

The only important thing to check is a potentially incorrect > commented above.

color: foreground,
),
),
Expanded(child: Container()),
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you still need the container now that there is no color? Or, could the Expanded be replaced with a Spacer? Also line 265 below.

I'm not sure, just throwing some ideas out there :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah makes sense. I'm going to just center the middle Container

double _offCenterOpacity = 1.0;
set offCenterOpacity(double value) {
assert(value != null);
assert(value > 0);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be value >= 0? Looking at your comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah forgot to change it. nice catch!

@override
Widget build(BuildContext context) {
Widget result = DefaultTextStyle(
final Color resolvedBackgroundColor = widget.backgroundColor == null
Copy link
Contributor

Choose a reason for hiding this comment

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

Anything to change now that that PR has been merged?

@@ -1 +1 @@
49f8198b72f6e12c65fe1db2e46162de0204e671
38e117bcd79860a3f239872c579acac716e70d49
Copy link
Contributor

Choose a reason for hiding this comment

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

This commit does not appear to exist in https://github.com/flutter/goldens/commits/master which is causing these golden file tests to fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah sorry I haven't merged the golden PR yet. I changed the golden hash to prevent flutter test from resetting the head to master so I can test with my golden fork. I'll update it once the golden PR is merged.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

LongCatIsLooong added a commit to flutter/goldens that referenced this pull request Sep 25, 2019
_paintChildCylindrically(context, offset, child, transform, offsetToCenter);
else
final bool shouldApplyOffCenterDim = offCenterOpacity < 1;
if (useMagnifier || shouldApplyOffCenterDim)
Copy link
Contributor

Choose a reason for hiding this comment

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

This would be a good place for extra curly braces

magnifierTopLinePosition);

// Clipping the part in the center.
context.pushClipRect(
Copy link
Contributor

Choose a reason for hiding this comment

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

Formatting suggestion:

      context.pushClipRect(
        needsCompositing,
        offset,
        centerRect,
        (PaintingContext context, Offset offset) {
          context.pushTransform(
            needsCompositing,
            offset,
            _magnifyTransform(),
            (PaintingContext context, Offset offset) {
              context.paintChild(child, offset + untransformedPaintingCoordinates);
            },
          );
        },
      );

},
offCenterOpacity == 1
? innerPainter
: (PaintingContext context, Offset offset) => context.pushOpacity(offset, (offCenterOpacity * 255).round(), innerPainter),
Copy link
Contributor

Choose a reason for hiding this comment

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

Factoring innerPaint out into a local function (with a helpful comment!) seems like a good idea. Maybe do the same for the other clause. Also: prefer => for one-liners that return a value.

///
/// Must be greater than or equal to 0, and less than or equal to 1.
/// {@endtemplate}
double get offCenterOpacity => _offCenterOpacity;
Copy link
Contributor

Choose a reason for hiding this comment

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

I wish we had a better name for this property - "off center" sounds a bit like askew.

Maybe overAndUnderCenterOpacity?

Copy link
Contributor

@Piinks Piinks left a comment

Choose a reason for hiding this comment

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

Goldens look good to me! Thanks! The bot may notify you about triage on Flutter Gold when this lands. Let me know if you have any questions. :)

@LongCatIsLooong
Copy link
Contributor Author

9c6dd0d seems to cause the golden test to fail

@dannyvalentesonos
Copy link
Contributor

@LongCatIsLooong
In your description, you wrote:

Disable the gradient painting when the background is null, because it looks really bad when the background is dark and backgroundColor = null

which to me means that gradient painting is only disabled when background is null, however, it seems like you removed the gradient entirely, and it's now impossible to get the same gradient effect as before. Am I right?

If so, this causes a problem for me and how I was using this widget. Is there a reason for that?

Thanks!

@LongCatIsLooong
Copy link
Contributor Author

@dannyvalentesonos yes the gradient was removed entirely. The gradient has hardcoded colors that didn't work well with a dark background so it was removed.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 31, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

c: API break Backwards-incompatible API changes f: cupertino flutter/packages/flutter/cupertino repository framework flutter/packages/flutter repository. See also f: labels. will affect goldens Changes to golden files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants