Skip to content

Commit ba48960

Browse files
authored
Fixed an issue with FilterChip's changing size when selected due to border size. (#111916)
1 parent 7f6c111 commit ba48960

File tree

4 files changed

+44
-3
lines changed

4 files changed

+44
-3
lines changed

dev/tools/gen_defaults/lib/filter_chip_template.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class _${blockName}DefaultsM3 extends ChipThemeData {
5757
? isEnabled
5858
? ${border('$tokenGroup$variant.unselected.outline')}
5959
: ${border('$tokenGroup$variant.disabled.unselected.outline')}
60-
: null;
60+
: const BorderSide(color: Colors.transparent);
6161
6262
@override
6363
IconThemeData? get iconTheme => IconThemeData(

packages/flutter/lib/src/material/choice_chip.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:flutter/widgets.dart';
77

88
import 'chip.dart';
99
import 'chip_theme.dart';
10+
import 'colors.dart';
1011
import 'debug.dart';
1112
import 'theme.dart';
1213
import 'theme_data.dart';
@@ -236,7 +237,7 @@ class _ChoiceChipDefaultsM3 extends ChipThemeData {
236237
? isEnabled
237238
? BorderSide(color: Theme.of(context).colorScheme.outline)
238239
: BorderSide(color: Theme.of(context).colorScheme.onSurface.withOpacity(0.12))
239-
: null;
240+
: const BorderSide(color: Colors.transparent);
240241

241242
@override
242243
IconThemeData? get iconTheme => IconThemeData(

packages/flutter/lib/src/material/filter_chip.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:flutter/widgets.dart';
77

88
import 'chip.dart';
99
import 'chip_theme.dart';
10+
import 'colors.dart';
1011
import 'debug.dart';
1112
import 'theme.dart';
1213
import 'theme_data.dart';
@@ -245,7 +246,7 @@ class _FilterChipDefaultsM3 extends ChipThemeData {
245246
? isEnabled
246247
? BorderSide(color: Theme.of(context).colorScheme.outline)
247248
: BorderSide(color: Theme.of(context).colorScheme.onSurface.withOpacity(0.12))
248-
: null;
249+
: const BorderSide(color: Colors.transparent);
249250

250251
@override
251252
IconThemeData? get iconTheme => IconThemeData(

packages/flutter/test/material/filter_chip_test.dart

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,43 @@ void main() {
172172
await tester.pumpWidget(wrapForChip(child: FilterChip(label: label, onSelected: (bool b) { }, clipBehavior: Clip.antiAlias)));
173173
checkChipMaterialClipBehavior(tester, Clip.antiAlias);
174174
});
175+
176+
testWidgets('M3 width should not change with selection', (WidgetTester tester) async {
177+
// Regression tests for: https://github.com/flutter/flutter/issues/110645
178+
179+
// For the text "FilterChip" the chip should default to 175 regardless of selection.
180+
const int expectedWidth = 175;
181+
182+
// Unselected
183+
await tester.pumpWidget(MaterialApp(
184+
theme: ThemeData(useMaterial3: true),
185+
home: Material(
186+
child: Center(
187+
child: FilterChip(
188+
label: const Text('FilterChip'),
189+
showCheckmark: false,
190+
onSelected: (bool _) {},
191+
)
192+
),
193+
),
194+
));
195+
expect(tester.getSize(find.byType(FilterChip)).width, expectedWidth);
196+
197+
// Selected
198+
await tester.pumpWidget(MaterialApp(
199+
theme: ThemeData(useMaterial3: true),
200+
home: Material(
201+
child: Center(
202+
child: FilterChip(
203+
label: const Text('FilterChip'),
204+
showCheckmark: false,
205+
selected: true,
206+
onSelected: (bool _) {},
207+
)
208+
),
209+
),
210+
));
211+
await tester.pumpAndSettle();
212+
expect(tester.getSize(find.byType(FilterChip)).width, expectedWidth);
213+
});
175214
}

0 commit comments

Comments
 (0)