Unverified Commit 62adfcf7 authored by Taha Tesser's avatar Taha Tesser Committed by GitHub

Fix `RawChip` doesn't use `ChipTheme.showCheckmark` value (#131257)

fixes [`RawChip` doesn't use `ChipThemeData.showCheckmark` value](https://github.com/flutter/flutter/issues/119163)

### Description

`RawChip.showCheckmark` is nullable yet the constructor falsely assigns a default which breaks `ChipTheme` support. This PR removes the falsely assigned default value.

### Code sample

<details> 
<summary>expand to view the code sample</summary> 

```dart
import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      theme: ThemeData(useMaterial3: true,
        chipTheme: const ChipThemeData(
          showCheckmark: false,
        )
      ),
      home: const Example(),
    );
  }
}

class Example extends StatelessWidget {
  const Example({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Sample'),
      ),
      body: Center(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceEvenly,
          children: <Widget>[
            const RawChip(
              selected: true,
              label: Text('RawChip'),
            ),
            FilterChip(
              selected: true,
              label: const Text('RawChip'), onSelected: (bool value) {  },
            ),
          ],
        ),
      ),
    );
  }
}

``` 
	
</details>

### Before
![before](https://github.com/flutter/flutter/assets/48603081/c8050c28-d988-4c72-8e0a-6455aa02d119)

### After

![after](https://github.com/flutter/flutter/assets/48603081/d5e83e81-6c12-4594-a2fd-8f113d6c9b54)
parent 9def8f6b
......@@ -748,7 +748,7 @@ class RawChip extends StatefulWidget
this.surfaceTintColor,
this.iconTheme,
this.selectedShadowColor,
this.showCheckmark = true,
this.showCheckmark,
this.checkmarkColor,
this.avatarBorder = const CircleBorder(),
@Deprecated(
......
......@@ -71,6 +71,7 @@ void main() {
expect(themeData.brightness, null);
expect(themeData.elevation, null);
expect(themeData.pressElevation, null);
expect(themeData.iconTheme, null);
});
testWidgetsWithLeakTracking('Default ChipThemeData debugFillProperties', (WidgetTester tester) async {
......@@ -108,6 +109,7 @@ void main() {
brightness: Brightness.dark,
elevation: 5,
pressElevation: 6,
iconTheme: IconThemeData(color: Color(0xffffff10)),
).debugFillProperties(builder);
final List<String> description = builder.properties
......@@ -115,7 +117,7 @@ void main() {
.map((DiagnosticsNode node) => node.toString())
.toList();
expect(description, <String>[
expect(description, equalsIgnoringHashCodes(<String>[
'color: MaterialStatePropertyAll(Color(0xfffffff0))',
'backgroundColor: Color(0xfffffff1)',
'deleteIconColor: Color(0xfffffff2)',
......@@ -136,7 +138,8 @@ void main() {
'brightness: dark',
'elevation: 5.0',
'pressElevation: 6.0',
]);
'iconTheme: IconThemeData#00000(color: Color(0xffffff10))'
]));
});
testWidgetsWithLeakTracking('Chip uses ThemeData chip theme', (WidgetTester tester) async {
......@@ -868,6 +871,63 @@ void main() {
// Enabled & selected chip should have the provided selectedColor.
expect(getMaterialBox(tester), paints..rrect(color: chipTheme.selectedColor));
});
// This is a regression test for https://github.com/flutter/flutter/issues/119163.
testWidgetsWithLeakTracking('RawChip respects checkmark properties from ChipTheme', (WidgetTester tester) async {
Widget buildRawChip({ChipThemeData? chipTheme}) {
return MaterialApp(
theme: ThemeData.light(useMaterial3: false).copyWith(
chipTheme: chipTheme,
),
home: Directionality(
textDirection: TextDirection.ltr,
child: Material(
child: Center(
child: RawChip(
selected: true,
label: const SizedBox(width: 100, height: 100),
onSelected: (bool newValue) { },
),
),
),
),
);
}
// Test that the checkmark is painted.
await tester.pumpWidget(buildRawChip(
chipTheme: const ChipThemeData(
checkmarkColor: Color(0xffff0000),
),
));
RenderBox materialBox = getMaterialBox(tester);
expect(
materialBox,
paints..path(
color: const Color(0xffff0000),
style: PaintingStyle.stroke,
),
);
// Test that the checkmark is not painted when ChipThemeData.showCheckmark is false.
await tester.pumpWidget(buildRawChip(
chipTheme: const ChipThemeData(
showCheckmark: false,
checkmarkColor: Color(0xffff0000),
),
));
await tester.pumpAndSettle();
materialBox = getMaterialBox(tester);
expect(
materialBox,
isNot(paints..path(
color: const Color(0xffff0000),
style: PaintingStyle.stroke,
)),
);
});
}
class _MaterialStateOutlinedBorder extends StadiumBorder implements MaterialStateOutlinedBorder {
......
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