Skip to content

Commit f65f541

Browse files
QuncCccccccaseycrogers
authored andcommitted
Update the default outline color for OutlinedButton (flutter#138768)
Fix b/311343182 This is to update the default outline for `OutlinedButton`. When the button is focused, the outline color should be primary color.
1 parent 0877bb4 commit f65f541

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
lines changed

dev/tools/gen_defaults/generated/used_tokens.csv

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Versions used, v0_162, v0_158
1+
Versions used, v0_162, v0_202, v0_158
22
md.comp.assist-chip.container.shape,
33
md.comp.assist-chip.container.surface-tint-layer.color,
44
md.comp.assist-chip.elevated.container.elevation,
@@ -453,6 +453,7 @@ md.comp.outlined-button.disabled.label-text.color,
453453
md.comp.outlined-button.disabled.label-text.opacity,
454454
md.comp.outlined-button.disabled.outline.color,
455455
md.comp.outlined-button.disabled.outline.opacity,
456+
md.comp.outlined-button.focus.outline.color,
456457
md.comp.outlined-button.focus.state-layer.color,
457458
md.comp.outlined-button.focus.state-layer.opacity,
458459
md.comp.outlined-button.hover.state-layer.color,

dev/tools/gen_defaults/lib/button_template.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ ${tokenAvailable("$tokenGroup.outline.color") ? '''
136136
if (states.contains(MaterialState.disabled)) {
137137
return ${border("$tokenGroup.disabled.outline")};
138138
}
139+
if (states.contains(MaterialState.focused)) {
140+
return ${border('$tokenGroup.focus.outline')};
141+
}
139142
return ${border("$tokenGroup.outline")};
140143
});''' : '''
141144
// No default side'''}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,9 @@ class _OutlinedButtonDefaultsM3 extends ButtonStyle {
545545
if (states.contains(MaterialState.disabled)) {
546546
return BorderSide(color: _colors.onSurface.withOpacity(0.12));
547547
}
548+
if (states.contains(MaterialState.focused)) {
549+
return BorderSide(color: _colors.primary);
550+
}
548551
return BorderSide(color: _colors.outline);
549552
});
550553

packages/flutter/test/material/outlined_button_test.dart

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ void main() {
259259
});
260260

261261
testWidgetsWithLeakTracking('Does OutlinedButton work with focus', (WidgetTester tester) async {
262+
final ThemeData theme = ThemeData();
263+
final ColorScheme colors = theme.colorScheme;
262264
const Color focusColor = Color(0xff001122);
263265

264266
Color? getOverlayColor(Set<MaterialState> states) {
@@ -267,9 +269,9 @@ void main() {
267269

268270
final FocusNode focusNode = FocusNode(debugLabel: 'OutlinedButton Node');
269271
await tester.pumpWidget(
270-
Directionality(
271-
textDirection: TextDirection.ltr,
272-
child: OutlinedButton(
272+
MaterialApp(
273+
theme: theme,
274+
home: OutlinedButton(
273275
style: ButtonStyle(
274276
overlayColor: MaterialStateProperty.resolveWith<Color?>(getOverlayColor),
275277
),
@@ -287,10 +289,21 @@ void main() {
287289
final RenderObject inkFeatures = tester.allRenderObjects.firstWhere((RenderObject object) => object.runtimeType.toString() == '_RenderInkFeatures');
288290
expect(inkFeatures, paints..rect(color: focusColor));
289291

292+
final Finder buttonMaterial = find.descendant(
293+
of: find.byType(OutlinedButton),
294+
matching: find.byType(Material),
295+
);
296+
297+
final Material material = tester.widget<Material>(buttonMaterial);
298+
299+
expect(material.shape, StadiumBorder(side: BorderSide(color: colors.primary)));
300+
290301
focusNode.dispose();
291302
});
292303

293304
testWidgetsWithLeakTracking('Does OutlinedButton work with autofocus', (WidgetTester tester) async {
305+
final ThemeData theme = ThemeData();
306+
final ColorScheme colors = theme.colorScheme;
294307
const Color focusColor = Color(0xff001122);
295308

296309
Color? getOverlayColor(Set<MaterialState> states) {
@@ -299,9 +312,9 @@ void main() {
299312

300313
final FocusNode focusNode = FocusNode(debugLabel: 'OutlinedButton Node');
301314
await tester.pumpWidget(
302-
Directionality(
303-
textDirection: TextDirection.ltr,
304-
child: OutlinedButton(
315+
MaterialApp(
316+
theme: theme,
317+
home: OutlinedButton(
305318
autofocus: true,
306319
style: ButtonStyle(
307320
overlayColor: MaterialStateProperty.resolveWith<Color?>(getOverlayColor),
@@ -319,6 +332,15 @@ void main() {
319332
final RenderObject inkFeatures = tester.allRenderObjects.firstWhere((RenderObject object) => object.runtimeType.toString() == '_RenderInkFeatures');
320333
expect(inkFeatures, paints..rect(color: focusColor));
321334

335+
336+
final Finder buttonMaterial = find.descendant(
337+
of: find.byType(OutlinedButton),
338+
matching: find.byType(Material),
339+
);
340+
341+
final Material material = tester.widget<Material>(buttonMaterial);
342+
343+
expect(material.shape, StadiumBorder(side: BorderSide(color: colors.primary)));
322344
focusNode.dispose();
323345
});
324346

0 commit comments

Comments
 (0)