From 62adfcf737b289f376f66bb2df0747b0b7ce8916 Mon Sep 17 00:00:00 2001 From: Taha Tesser Date: Tue, 25 Jul 2023 18:37:17 +0300 Subject: [PATCH] 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
expand to view the code sample ```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: [ const RawChip( selected: true, label: Text('RawChip'), ), FilterChip( selected: true, label: const Text('RawChip'), onSelected: (bool value) { }, ), ], ), ), ); } } ```
### 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) --- packages/flutter/lib/src/material/chip.dart | 2 +- .../test/material/chip_theme_test.dart | 64 ++++++++++++++++++- 2 files changed, 63 insertions(+), 3 deletions(-) diff --git a/packages/flutter/lib/src/material/chip.dart b/packages/flutter/lib/src/material/chip.dart index adbe712737..3e1eb6d7ba 100644 --- a/packages/flutter/lib/src/material/chip.dart +++ b/packages/flutter/lib/src/material/chip.dart @@ -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( diff --git a/packages/flutter/test/material/chip_theme_test.dart b/packages/flutter/test/material/chip_theme_test.dart index 5da0b0a428..3cd47209e6 100644 --- a/packages/flutter/test/material/chip_theme_test.dart +++ b/packages/flutter/test/material/chip_theme_test.dart @@ -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 description = builder.properties @@ -115,7 +117,7 @@ void main() { .map((DiagnosticsNode node) => node.toString()) .toList(); - expect(description, [ + expect(description, equalsIgnoringHashCodes([ '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 {