diff --git a/packages/flutter/lib/src/material/back_button.dart b/packages/flutter/lib/src/material/back_button.dart index 279f4be3de..4666ac814e 100644 --- a/packages/flutter/lib/src/material/back_button.dart +++ b/packages/flutter/lib/src/material/back_button.dart @@ -128,13 +128,20 @@ class BackButton extends StatelessWidget { /// * [IconButton], to create other material design icon buttons. class CloseButton extends StatelessWidget { /// Creates a Material Design close button. - const CloseButton({ Key key }) : super(key: key); + const CloseButton({ Key key, this.color }) : super(key: key); + + /// The color to use for the icon. + /// + /// Defaults to the [IconThemeData.color] specified in the ambient [IconTheme], + /// which usually matches the ambient [Theme]'s [ThemeData.iconTheme]. + final Color color; @override Widget build(BuildContext context) { assert(debugCheckHasMaterialLocalizations(context)); return IconButton( icon: const Icon(Icons.close), + color: color, tooltip: MaterialLocalizations.of(context).closeButtonTooltip, onPressed: () { Navigator.maybePop(context); diff --git a/packages/flutter/test/material/back_button_test.dart b/packages/flutter/test/material/back_button_test.dart index dea09f789e..767767e71e 100644 --- a/packages/flutter/test/material/back_button_test.dart +++ b/packages/flutter/test/material/back_button_test.dart @@ -69,7 +69,6 @@ void main() { final Key iOSKey = UniqueKey(); final Key androidKey = UniqueKey(); - await tester.pumpWidget( MaterialApp( home: Column( @@ -92,6 +91,24 @@ void main() { expect(iOSIcon == androidIcon, false); }); + testWidgets('BackButton color', (WidgetTester tester) async { + await tester.pumpWidget( + const MaterialApp( + home: Material( + child: BackButton( + color: Colors.blue, + ), + ), + ), + ); + + final RichText iconText = tester.firstWidget(find.descendant( + of: find.byType(BackButton), + matching: find.byType(RichText) + )); + expect(iconText.text.style.color, Colors.blue); + }); + testWidgets('BackButton semantics', (WidgetTester tester) async { final SemanticsHandle handle = tester.ensureSemantics(); await tester.pumpWidget( @@ -123,4 +140,22 @@ void main() { )); handle.dispose(); }); + + testWidgets('CloseButton color', (WidgetTester tester) async { + await tester.pumpWidget( + const MaterialApp( + home: Material( + child: CloseButton( + color: Colors.red, + ), + ), + ), + ); + + final RichText iconText = tester.firstWidget(find.descendant( + of: find.byType(CloseButton), + matching: find.byType(RichText) + )); + expect(iconText.text.style.color, Colors.red); + }); }