Expose a color property to CloseButton (#49256)

This commit is contained in:
Darren Austin 2020-01-24 19:08:02 -08:00 committed by Flutter GitHub Bot
parent bc5c46438a
commit 782f9cceac
2 changed files with 44 additions and 2 deletions

View File

@ -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);

View File

@ -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);
});
}