Skip to content

Commit 782f9cc

Browse files
darrenaustinfluttergithubbot
authored andcommitted
Expose a color property to CloseButton (flutter#49256)
1 parent bc5c464 commit 782f9cc

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,20 @@ class BackButton extends StatelessWidget {
128128
/// * [IconButton], to create other material design icon buttons.
129129
class CloseButton extends StatelessWidget {
130130
/// Creates a Material Design close button.
131-
const CloseButton({ Key key }) : super(key: key);
131+
const CloseButton({ Key key, this.color }) : super(key: key);
132+
133+
/// The color to use for the icon.
134+
///
135+
/// Defaults to the [IconThemeData.color] specified in the ambient [IconTheme],
136+
/// which usually matches the ambient [Theme]'s [ThemeData.iconTheme].
137+
final Color color;
132138

133139
@override
134140
Widget build(BuildContext context) {
135141
assert(debugCheckHasMaterialLocalizations(context));
136142
return IconButton(
137143
icon: const Icon(Icons.close),
144+
color: color,
138145
tooltip: MaterialLocalizations.of(context).closeButtonTooltip,
139146
onPressed: () {
140147
Navigator.maybePop(context);

packages/flutter/test/material/back_button_test.dart

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ void main() {
6969
final Key iOSKey = UniqueKey();
7070
final Key androidKey = UniqueKey();
7171

72-
7372
await tester.pumpWidget(
7473
MaterialApp(
7574
home: Column(
@@ -92,6 +91,24 @@ void main() {
9291
expect(iOSIcon == androidIcon, false);
9392
});
9493

94+
testWidgets('BackButton color', (WidgetTester tester) async {
95+
await tester.pumpWidget(
96+
const MaterialApp(
97+
home: Material(
98+
child: BackButton(
99+
color: Colors.blue,
100+
),
101+
),
102+
),
103+
);
104+
105+
final RichText iconText = tester.firstWidget(find.descendant(
106+
of: find.byType(BackButton),
107+
matching: find.byType(RichText)
108+
));
109+
expect(iconText.text.style.color, Colors.blue);
110+
});
111+
95112
testWidgets('BackButton semantics', (WidgetTester tester) async {
96113
final SemanticsHandle handle = tester.ensureSemantics();
97114
await tester.pumpWidget(
@@ -123,4 +140,22 @@ void main() {
123140
));
124141
handle.dispose();
125142
});
143+
144+
testWidgets('CloseButton color', (WidgetTester tester) async {
145+
await tester.pumpWidget(
146+
const MaterialApp(
147+
home: Material(
148+
child: CloseButton(
149+
color: Colors.red,
150+
),
151+
),
152+
),
153+
);
154+
155+
final RichText iconText = tester.firstWidget(find.descendant(
156+
of: find.byType(CloseButton),
157+
matching: find.byType(RichText)
158+
));
159+
expect(iconText.text.style.color, Colors.red);
160+
});
126161
}

0 commit comments

Comments
 (0)