diff --git a/packages/flutter/lib/src/material/chip.dart b/packages/flutter/lib/src/material/chip.dart index 3e1eb6d7ba..b3bc897845 100644 --- a/packages/flutter/lib/src/material/chip.dart +++ b/packages/flutter/lib/src/material/chip.dart @@ -992,13 +992,21 @@ class _RawChipState extends State with MaterialStateMixin, TickerProvid OutlinedBorder _getShape(ThemeData theme, ChipThemeData chipTheme, ChipThemeData chipDefaults) { final BorderSide? resolvedSide = MaterialStateProperty.resolveAs(widget.side, materialStates) - ?? MaterialStateProperty.resolveAs(chipTheme.side, materialStates) - ?? MaterialStateProperty.resolveAs(chipDefaults.side, materialStates); + ?? MaterialStateProperty.resolveAs(chipTheme.side, materialStates); final OutlinedBorder resolvedShape = MaterialStateProperty.resolveAs(widget.shape, materialStates) ?? MaterialStateProperty.resolveAs(chipTheme.shape, materialStates) ?? MaterialStateProperty.resolveAs(chipDefaults.shape, materialStates) + // TODO(tahatesser): Remove this fallback when Material 2 is deprecated. ?? const StadiumBorder(); - return resolvedShape.copyWith(side: resolvedSide); + // If the side is provided, shape uses the provided side. + if (resolvedSide != null) { + return resolvedShape.copyWith(side: resolvedSide); + } + // If the side is not provided and the shape's side is not [BorderSide.none], + // then the shape's side is used. Otherwise, the default side is used. + return resolvedShape.side != BorderSide.none + ? resolvedShape + : resolvedShape.copyWith(side: chipDefaults.side); } Color? resolveColor({ diff --git a/packages/flutter/test/material/chip_test.dart b/packages/flutter/test/material/chip_test.dart index d098936aa1..0d8c057640 100644 --- a/packages/flutter/test/material/chip_test.dart +++ b/packages/flutter/test/material/chip_test.dart @@ -3503,6 +3503,85 @@ void main() { expect(calledDelete, isTrue); }); + // This is a regression test for https://github.com/flutter/flutter/pull/133615. + testWidgets('Material3 - Custom shape without provided side uses default side', (WidgetTester tester) async { + final ThemeData theme = ThemeData(useMaterial3: true); + await tester.pumpWidget( + MaterialApp( + theme: theme, + home: const Material( + child: Center( + child: RawChip( + // No side provided. + shape: StadiumBorder(), + label: Text('RawChip'), + ), + ), + ), + ), + ); + + // Chip should have the default side. + expect( + getMaterial(tester).shape, + StadiumBorder(side: BorderSide(color: theme.colorScheme.outline)), + ); + }); + + testWidgets("Material3 - RawChip.shape's side is used when provided", (WidgetTester tester) async { + Widget buildChip({ OutlinedBorder? shape, BorderSide? side }) { + return MaterialApp( + theme: ThemeData(useMaterial3: true), + home: Material( + child: Center( + child: RawChip( + shape: shape, + side: side, + label: const Text('RawChip'), + ), + ), + ), + ); + } + + // Test [RawChip.shape] with a side. + await tester.pumpWidget(buildChip( + shape: const RoundedRectangleBorder( + side: BorderSide(color: Color(0xffff00ff)), + borderRadius: BorderRadius.all(Radius.circular(7.0)), + )), + ); + + // Chip should have the provided shape and the side from [RawChip.shape]. + expect( + getMaterial(tester).shape, + const RoundedRectangleBorder( + side: BorderSide(color: Color(0xffff00ff)), + borderRadius: BorderRadius.all(Radius.circular(7.0)), + ), + ); + + // Test [RawChip.shape] with a side and [RawChip.side]. + await tester.pumpWidget(buildChip( + shape: const RoundedRectangleBorder( + side: BorderSide(color: Color(0xffff00ff)), + borderRadius: BorderRadius.all(Radius.circular(7.0)), + ), + side: const BorderSide(color: Color(0xfffff000))), + ); + await tester.pumpAndSettle(); + + // Chip use shape from [RawChip.shape] and the side from [RawChip.side]. + // [RawChip.shape]'s side should be ignored. + expect( + getMaterial(tester).shape, + const RoundedRectangleBorder( + side: BorderSide(color: Color(0xfffff000)), + borderRadius: BorderRadius.all(Radius.circular(7.0)), + ), + ); + }); + group('Material 2', () { // These tests are only relevant for Material 2. Once Material 2 // support is deprecated and the APIs are removed, these tests diff --git a/packages/flutter/test/material/chip_theme_test.dart b/packages/flutter/test/material/chip_theme_test.dart index 2303b56478..4ff0c5c317 100644 --- a/packages/flutter/test/material/chip_theme_test.dart +++ b/packages/flutter/test/material/chip_theme_test.dart @@ -928,6 +928,64 @@ void main() { )), ); }); + + testWidgets("Material3 - RawChip.shape's side is used when provided", (WidgetTester tester) async { + Widget buildChip({ OutlinedBorder? shape, BorderSide? side }) { + return MaterialApp( + theme: ThemeData( + useMaterial3: true, + chipTheme: ChipThemeData( + shape: shape, + side: side, + ), + ), + home: const Material( + child: Center( + child: RawChip( + label: Text('RawChip'), + ), + ), + ), + ); + } + + // Test [RawChip.shape] with a side. + await tester.pumpWidget(buildChip( + shape: const RoundedRectangleBorder( + side: BorderSide(color: Color(0xffff00ff)), + borderRadius: BorderRadius.all(Radius.circular(7.0)), + )), + ); + + // Chip should have the provided shape and the side from [RawChip.shape]. + expect( + getMaterial(tester).shape, + const RoundedRectangleBorder( + side: BorderSide(color: Color(0xffff00ff)), + borderRadius: BorderRadius.all(Radius.circular(7.0)), + ), + ); + + // Test [RawChip.shape] with a side and [RawChip.side]. + await tester.pumpWidget(buildChip( + shape: const RoundedRectangleBorder( + side: BorderSide(color: Color(0xffff00ff)), + borderRadius: BorderRadius.all(Radius.circular(7.0)), + ), + side: const BorderSide(color: Color(0xfffff000))), + ); + await tester.pumpAndSettle(); + + // Chip use shape from [RawChip.shape] and the side from [RawChip.side]. + // [RawChip.shape]'s side should be ignored. + expect( + getMaterial(tester).shape, + const RoundedRectangleBorder( + side: BorderSide(color: Color(0xfffff000)), + borderRadius: BorderRadius.all(Radius.circular(7.0)), + ), + ); + }); } class _MaterialStateOutlinedBorder extends StadiumBorder implements MaterialStateOutlinedBorder {