From effa7d5280000c2974c334b2d75a3e72cce1248c Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Wed, 3 Mar 2021 17:39:03 -0800 Subject: [PATCH] use textdirection for gradient of ShapeDecoration (#77186) --- .../lib/src/painting/shape_decoration.dart | 2 +- .../test/widgets/shape_decoration_test.dart | 26 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/painting/shape_decoration.dart b/packages/flutter/lib/src/painting/shape_decoration.dart index dc3f43eb46..01299700bb 100644 --- a/packages/flutter/lib/src/painting/shape_decoration.dart +++ b/packages/flutter/lib/src/painting/shape_decoration.dart @@ -329,7 +329,7 @@ class _ShapeDecorationPainter extends BoxPainter { _interiorPaint!.color = _decoration.color!; } if (_decoration.gradient != null) - _interiorPaint!.shader = _decoration.gradient!.createShader(rect); + _interiorPaint!.shader = _decoration.gradient!.createShader(rect, textDirection: textDirection); if (_decoration.shadows != null) { if (_shadowCount == null) { _shadowCount = _decoration.shadows!.length; diff --git a/packages/flutter/test/widgets/shape_decoration_test.dart b/packages/flutter/test/widgets/shape_decoration_test.dart index c45962ddff..0f486e03ea 100644 --- a/packages/flutter/test/widgets/shape_decoration_test.dart +++ b/packages/flutter/test/widgets/shape_decoration_test.dart @@ -114,6 +114,32 @@ Future main() async { ); }); + testWidgets('Does not crash with directional gradient', (WidgetTester tester) async { + // Regression test for https://github.com/flutter/flutter/issues/76967. + + await tester.pumpWidget( + const Directionality( + textDirection: TextDirection.rtl, + child: DecoratedBox( + decoration: ShapeDecoration( + gradient: RadialGradient( + focal: AlignmentDirectional(0, 1), + focalRadius: 5, + radius: 2, + colors: [Colors.red, Colors.black], + stops: [0.0, 0.4], + ), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(8.0)), + ), + ), + ), + ), + ); + + expect(tester.takeException(), isNull); + }); + test('ShapeDecoration equality', () { const ShapeDecoration a = ShapeDecoration( color: Color(0xFFFFFFFF),