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

Add Non-Uniform Border to Border. #121921

Merged
merged 6 commits into from Mar 24, 2023
Merged

Conversation

bernaferrari
Copy link
Contributor

@bernaferrari bernaferrari commented Mar 4, 2023

Fix #12583.
Fix #109954.

Exactly like Figma:

image

image

What if it has multiple colors + borderRadius? It will crash as usual.
Side effects: material data tables will paint faster, because drrect > path.

@flutter-dashboard flutter-dashboard bot added the framework flutter/packages/flutter repository. See also f: labels. label Mar 4, 2023
@bernaferrari bernaferrari force-pushed the Non-Uniform branch 8 times, most recently from 2c66e80 to 8e822a2 Compare March 5, 2023 16:15
@flutter-dashboard flutter-dashboard bot added the f: material design flutter/packages/flutter/material repository. label Mar 5, 2023
@bernaferrari bernaferrari force-pushed the Non-Uniform branch 3 times, most recently from 9c63189 to 7dfad4b Compare March 5, 2023 16:39
@@ -567,7 +632,7 @@ class Border extends BoxBorder {
assert(() {
if (!_strokeAlignIsUniform || top.strokeAlign != BorderSide.strokeAlignInside) {
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary('A Border can only draw strokeAlign different than BorderSide.strokeAlignInside on uniform borders.'),
ErrorSummary('A Border can only draw strokeAlign different than BorderSide.strokeAlignInside on borders with uniform colors.'),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

uniform colors/styles instead? Uniform colors is way more common and style == BorderStyle.none is kind of an invisible color.

Copy link
Contributor

Choose a reason for hiding this comment

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

But if we added a new border style, it might complicate things a lot. For instance, what if we added a "striped" border style that drew diagonal caution stripes? Or a "dashed" border style? I think it would be better if it were both color and style.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks!

@bernaferrari bernaferrari force-pushed the Non-Uniform branch 2 times, most recently from 4bdeb98 to 7575642 Compare March 6, 2023 01:39
@bernaferrari bernaferrari marked this pull request as ready for review March 6, 2023 02:28
@bernaferrari
Copy link
Contributor Author

Hey @gspencergoog, did you miss me? 😛

@bernaferrari bernaferrari force-pushed the Non-Uniform branch 7 times, most recently from 11c6e01 to a288699 Compare March 19, 2023 16:06
@@ -567,7 +632,7 @@ class Border extends BoxBorder {
assert(() {
if (!_strokeAlignIsUniform || top.strokeAlign != BorderSide.strokeAlignInside) {
throw FlutterError.fromParts(<DiagnosticsNode>[
ErrorSummary('A Border can only draw strokeAlign different than BorderSide.strokeAlignInside on uniform borders.'),
ErrorSummary('A Border can only draw strokeAlign different than BorderSide.strokeAlignInside on borders with uniform colors.'),
Copy link
Contributor

Choose a reason for hiding this comment

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

But if we added a new border style, it might complicate things a lot. For instance, what if we added a "striped" border style that drew diagonal caution stripes? Or a "dashed" border style? I think it would be better if it were both color and style.

packages/flutter/lib/src/painting/box_border.dart Outdated Show resolved Hide resolved
packages/flutter/lib/src/painting/box_border.dart Outdated Show resolved Hide resolved
packages/flutter/lib/src/painting/box_border.dart Outdated Show resolved Hide resolved
packages/flutter/lib/src/painting/box_border.dart Outdated Show resolved Hide resolved
@@ -538,15 +578,25 @@ class Border extends BoxBorder {
}
}

// Allow painting non-uniform borders if the color is uniform.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Allow painting non-uniform borders if the color is uniform.
// Allow painting non-uniform borders if the shape is rectangular, and the color and style are uniform.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I'll allow BoxShape.circle. I've been trying to deprecate it for 8 months, but that will give a reason for it to exist.

Let me see if I can implement non-uniform border for circles.

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. Making tests.

// Allow painting non-uniform borders if the color is uniform.
//
// See also:
// * <https://pub.dev/packages/non_uniform_border>, a package that
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you move this "See also" to a real doc comment so people can see it?

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, check if you prefer in Border or paint (probably paint, right?).

end: BorderSide(width: 15, strokeAlign: BorderSide.strokeAlignOutside),
bottom: BorderSide(width: 20),
);
expect(nonUniformBorderDirectional.dimensions, const EdgeInsetsDirectional.fromSTEB(5, 5, 0, 20));
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you also test to make sure that it asserts when non-uniform borders of various types are tried? You don't have to test for the assert message itself, but at least that it asserts under the right conditions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yessss. Hold on.

@gspencergoog
Copy link
Contributor

Hey @gspencergoog, did you miss me? 😛

Of course! I love your PRs. :-)

@bernaferrari
Copy link
Contributor Author

bernaferrari commented Mar 20, 2023

Do you think BorderStyle.none could be considered as width == 0 (right now they are color == transparent)? If I make it the same as width == 0 in non-uniform borders, it is one less exception. Only uniform colors would need to be required.

Edit: ignore it for now. I think the implementation will be ugly.

@gspencergoog
Copy link
Contributor

Only uniform colors would need to be required.

Again, what happens if we add a new style?

Copy link
Contributor

@gspencergoog gspencergoog left a comment

Choose a reason for hiding this comment

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

32384589-a60f0e74-c078-11e7-9bc1-e5b5287aea9d

@@ -212,7 +212,8 @@ abstract class BoxBorder extends ShapeBorder {
///
/// See also:
///
/// * [paintBorder], which is used if the border is not uniform.
/// * [paintBorder], which is used if the border has non-uniform colors or styles and no borderRadius.
/// * [Border.paint], which is the similar method in [Border] with additional comments.
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you mean by "additional comments"? More context? I'd reword this in any case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. I'll reword. BorderDirectional is shorter and gives less detail on what each parameter do than the equivalent Border.

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. Replacement is:

[Border.paint], similar to this method, includes additional comments and provides more details on each parameter than described here.

packages/flutter/lib/src/painting/box_border.dart Outdated Show resolved Hide resolved
packages/flutter/test/painting/border_test.dart Outdated Show resolved Hide resolved
@bernaferrari bernaferrari force-pushed the Non-Uniform branch 5 times, most recently from 900dcf3 to acf8bef Compare March 23, 2023 14:50
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.

LGTM

@Piinks Piinks added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 23, 2023
@auto-submit auto-submit bot merged commit 5054b6e into flutter:master Mar 24, 2023
71 checks passed
@bernaferrari bernaferrari deleted the Non-Uniform branch March 24, 2023 01:41
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 24, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 10, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 10, 2023
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.
Projects
None yet
3 participants