Skip to content

Commit 9f90740

Browse files
authored
Improve assertion message in _MixedBorderRadius.resolve() (flutter#172100)
Replaces the generic assertion in `_MixedBorderRadius.resolve` with `debugCheckCanResolveTextDirection`. This change provides a more helpful and descriptive error message when the `TextDirection` is null, improving the developer experience by clearly stating why the resolution failed and how to fix it. Fixes: flutter#171815, also fixes: flutter#171812 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent 4ba3886 commit 9f90740

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

packages/flutter/lib/src/painting/border_radius.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ class _MixedBorderRadius extends BorderRadiusGeometry {
915915

916916
@override
917917
BorderRadius resolve(TextDirection? direction) {
918-
assert(direction != null);
918+
assert(debugCheckCanResolveTextDirection(direction, '$_MixedBorderRadius'));
919919
switch (direction!) {
920920
case TextDirection.rtl:
921921
return BorderRadius.only(

packages/flutter/test/painting/border_radius_test.dart

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,42 @@ void main() {
345345
);
346346
});
347347

348+
// to test _MixedBorderRadius using `add()` and `subtract()` methods
349+
test('resolve method throws detailed error when TextDirection is null', () {
350+
const BorderRadius a = BorderRadius.only(
351+
topLeft: Radius.elliptical(10.0, 20.0),
352+
topRight: Radius.elliptical(30.0, 40.0),
353+
bottomLeft: Radius.elliptical(50.0, 60.0),
354+
);
355+
const BorderRadiusDirectional b = BorderRadiusDirectional.only(
356+
topEnd: Radius.elliptical(100.0, 110.0),
357+
bottomStart: Radius.elliptical(120.0, 130.0),
358+
bottomEnd: Radius.elliptical(140.0, 150.0),
359+
);
360+
361+
expect(
362+
() => a.add(b).resolve(null),
363+
throwsA(
364+
isFlutterError.having(
365+
(FlutterError e) => e.message,
366+
'message',
367+
allOf(contains('No TextDirection found.'), contains('without a Directionality ancestor')),
368+
),
369+
),
370+
);
371+
372+
expect(
373+
() => b.subtract(a).resolve(null),
374+
throwsA(
375+
isFlutterError.having(
376+
(FlutterError e) => e.message,
377+
'message',
378+
allOf(contains('No TextDirection found.'), contains('without a Directionality ancestor')),
379+
),
380+
),
381+
);
382+
});
383+
348384
test('BorderRadiusDirectional.lerp() invariants', () {
349385
final BorderRadiusDirectional a = BorderRadiusDirectional.circular(10.0);
350386
final BorderRadiusDirectional b = BorderRadiusDirectional.circular(20.0);

0 commit comments

Comments
 (0)