Unverified Commit b7046b32 authored by Bernardo Ferrari's avatar Bernardo Ferrari Committed by GitHub

Improve and optimize non-uniform Borders. (#124417)

~~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 how `borderRadius.zero` to `borderRadius != 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.~~

<img width="448" alt="image" src="https://user-images.githubusercontent.com/351125/236550350-7499d758-5b44-40e6-9105-32671eb21998.png">

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.
parent fe9c7f4f
...@@ -1750,7 +1750,7 @@ void main() { ...@@ -1750,7 +1750,7 @@ void main() {
); );
expect( expect(
find.ancestor(of: find.byType(Table), matching: find.byType(Container)), find.ancestor(of: find.byType(Table), matching: find.byType(Container)),
paints..drrect(color: borderColor), paints..path(color: borderColor),
); );
expect( expect(
tester.getTopLeft(find.byType(Table)), tester.getTopLeft(find.byType(Table)),
......
...@@ -136,8 +136,9 @@ void main() { ...@@ -136,8 +136,9 @@ void main() {
testWidgets('Vertical Divider Test 2', (WidgetTester tester) async { testWidgets('Vertical Divider Test 2', (WidgetTester tester) async {
await tester.pumpWidget( await tester.pumpWidget(
const MaterialApp( MaterialApp(
home: Material( theme: ThemeData(useMaterial3: false),
home: const Material(
child: SizedBox( child: SizedBox(
height: 24.0, height: 24.0,
child: Row( child: Row(
......
...@@ -273,7 +273,7 @@ void main() { ...@@ -273,7 +273,7 @@ void main() {
expect(error.diagnostics.length, 1); expect(error.diagnostics.length, 1);
expect( expect(
error.diagnostics[0].toStringDeep(), error.diagnostics[0].toStringDeep(),
'A Border can only draw strokeAlign different than\nBorderSide.strokeAlignInside on borders with uniform colors and\nstyles.\n', 'A Border can only draw strokeAlign different than\nBorderSide.strokeAlignInside on borders with uniform colors.\n',
); );
}); });
...@@ -341,8 +341,8 @@ void main() { ...@@ -341,8 +341,8 @@ void main() {
// This falls into non-uniform border because of strokeAlign. // This falls into non-uniform border because of strokeAlign.
await tester.pumpWidget(buildWidget(border: allowedBorderVariations)); await tester.pumpWidget(buildWidget(border: allowedBorderVariations));
expect(tester.takeException(), isNull, expect(tester.takeException(), isAssertionError,
reason: 'Border with non-uniform strokeAlign should not fail.'); reason: 'Border with non-uniform strokeAlign should fail.');
await tester.pumpWidget(buildWidget( await tester.pumpWidget(buildWidget(
border: allowedBorderVariations, border: allowedBorderVariations,
...@@ -364,8 +364,8 @@ void main() { ...@@ -364,8 +364,8 @@ void main() {
borderRadius: BorderRadius.circular(25), borderRadius: BorderRadius.circular(25),
), ),
); );
expect(tester.takeException(), isAssertionError, expect(tester.takeException(), isNull,
reason: 'Border with non-uniform styles should fail with borderRadius.'); reason: 'Border with non-uniform styles should work with borderRadius.');
await tester.pumpWidget( await tester.pumpWidget(
buildWidget( buildWidget(
...@@ -381,6 +381,24 @@ void main() { ...@@ -381,6 +381,24 @@ void main() {
expect(tester.takeException(), isAssertionError, expect(tester.takeException(), isAssertionError,
reason: 'Border with non-uniform colors should fail with borderRadius.'); reason: 'Border with non-uniform colors should fail with borderRadius.');
await tester.pumpWidget(
buildWidget(
border: const Border(bottom: BorderSide(width: 0)),
borderRadius: BorderRadius.zero,
),
);
expect(tester.takeException(), isNull,
reason: 'Border with a side.width == 0 should work without borderRadius (hairline border).');
await tester.pumpWidget(
buildWidget(
border: const Border(bottom: BorderSide(width: 0)),
borderRadius: BorderRadius.circular(40),
),
);
expect(tester.takeException(), isAssertionError,
reason: 'Border with width == 0 and borderRadius should fail (hairline border).');
// Tests for BorderDirectional. // Tests for BorderDirectional.
const BorderDirectional allowedBorderDirectionalVariations = BorderDirectional( const BorderDirectional allowedBorderDirectionalVariations = BorderDirectional(
start: BorderSide(width: 5), start: BorderSide(width: 5),
...@@ -390,7 +408,7 @@ void main() { ...@@ -390,7 +408,7 @@ void main() {
); );
await tester.pumpWidget(buildWidget(border: allowedBorderDirectionalVariations)); await tester.pumpWidget(buildWidget(border: allowedBorderDirectionalVariations));
expect(tester.takeException(), isNull); expect(tester.takeException(), isAssertionError);
await tester.pumpWidget(buildWidget( await tester.pumpWidget(buildWidget(
border: allowedBorderDirectionalVariations, border: allowedBorderDirectionalVariations,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment