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
Improve and optimize non-uniform Borders. #124417
Conversation
EDIT: Ahh, I see you've updated the definitions of old and new on me. :-) OK, I'll take a look, but I think it would need to be less surprising than it currently is. |
For borderRadius there is no old way, it just crashes. |
914eb59
to
d5aa6dd
Compare
They could, by clipping (slow). But I limited the behavior to only work on top, left, bottom, right or top/bottom, right/left (but these are less important). Also, your solution wouldn't work for circular shape :( I think if this PR addressed top/left/right/bottom would be enough already. Because it is a very simple scenario (Border.only) and the current solution fails on that, since it defaults everything else to none. I changed from addressing "all cases" to addressing |
My biggest motivator is that Or a combination of a+b. What do you think @gspencergoog? |
By the principle of least surprise, I agree with @cedvdb. Even if it's slower, it's much less surprising. For one thing, the lerp between no border radius and border radius would need to be smooth, and I don't see how you can do that with your design, at least not in any pleasing way. |
What about supporting Border.only with a single visible color (and maybe Border.symmetrical), ignoring Border.only with multiple colors for now? |
That might work. What would that look like? |
When we merged it with borderRadius, we forgot the "default" of Border.only and Border.symmetrical is black + invisible by default. So I think we could support non-uniform borderStyle (BorderStyle.none). Border.only(top: ...) will fail with borderRadius because left/right/bottom are invisible with different colors. |
I think option B seems more reasonable. Option A seems like people will just wonder why the limitation exists. I mean, they'll wonder with either one, but I think it's easier to see the logic with Option B. |
e287dbd
to
5b0d24f
Compare
Up to this point, it wasn't supposed to trigger Google Testing. Now it might. Not using paintBorder (when possible) is much faster than using it. Goldens will also trigger. It is the path -> drrect difference. I painted 100k borders on each test. This PR is ~15-50% faster.
|
Nice! Let's see how bad the Google test fallout is. |
Fix divider test. Add exception.
62a907c
to
2513469
Compare
assert(borderRadius == null || borderRadius == BorderRadius.zero, | ||
'A hairline border like `BorderSide(width: 0.0, style: BorderStyle.solid)` can only be drawn when BorderRadius is zero or null.'); |
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 new assert broke app-bar in my app after updating to 3.16.
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.
@Hixie @bernaferrari is it a good idea to mention this change in breaking points page for 3.16?
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 you show the code? It isn't supposed to break anything because the behavior was wrong
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.
made a reproducible sample: https://dartpad.dev/?id=413770c667697ac3472fc03d12d4fe54
Issue: "FAQs" widget is not shown because of the new assert.
either setting the border-radius to zero or removing the BorderSide's with 0 width, fixes the problem. not sure why we were using border-side 0 in our code but code was in app-bar hence I noticed it when it glitched after stable update.
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, but the 0 as hidden is a bug, because flutter uses that for hairline border (I wish it were different but I can't change it because visual density depends on context), so instead of fixing to show it (which would be a bug for you), we fixed to assert to prevent problems in the future
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.
Same here. Not sure what was wrong with hairline borders, but we use them pretty extensively in our app and now they aren't visible anymore after updating to the latest Flutter version. Could you clarify what was the issue with drawing hairline borders with rounded corners?
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 an inconsistent behavior, I just updated to be consistent. The issue is that for any other corner it draws hairline on width = 0 and you can't draw it on non uniform, so I added an assert.
Using the same priority order as a Border without borderRadius, it is possible to draw them on top of each other. This is better than the current behavior (crash!) and would work well for a "one color on top, another on bottom" scenario.With this, if approved, we move the current number of possible exceptions from 4 to 1 (BoxShape.circle
+borderRadius
).It is kind of odd howborderRadius.zero
toborderRadius != BorderRadius.zero
change, but I think it is better than crashing. Alternatively, we just remove the "original function" and see if any goldens are affected.Another one for @gspencergoog. If this works, we could make the paint method public and re-use in the InputBorder PR (if that's also approved). Single line fix.