Snack color (#23255)
* added test
diff --git a/packages/flutter/lib/src/material/snack_bar.dart b/packages/flutter/lib/src/material/snack_bar.dart
index ccb217a..55c88ff 100644
--- a/packages/flutter/lib/src/material/snack_bar.dart
+++ b/packages/flutter/lib/src/material/snack_bar.dart
@@ -81,12 +81,21 @@
/// The [label] and [onPressed] arguments must be non-null.
const SnackBarAction({
Key key,
+ this.textColor,
+ this.disabledTextColor,
@required this.label,
@required this.onPressed,
}) : assert(label != null),
assert(onPressed != null),
super(key: key);
+ /// The button label color. If not provided, defaults to [accentColor].
+ final Color textColor;
+
+ /// The button disabled label color. This color is shown after the
+ /// [snackBarAction] is dismissed.
+ final Color disabledTextColor;
+
/// The button label.
final String label;
@@ -118,6 +127,8 @@
return FlatButton(
onPressed: _haveTriggeredAction ? null : _handlePressed,
child: Text(widget.label),
+ textColor: widget.textColor,
+ disabledTextColor: widget.disabledTextColor,
);
}
}
diff --git a/packages/flutter/test/material/snack_bar_test.dart b/packages/flutter/test/material/snack_bar_test.dart
index cf1d55d..38e403e 100644
--- a/packages/flutter/test/material/snack_bar_test.dart
+++ b/packages/flutter/test/material/snack_bar_test.dart
@@ -296,6 +296,50 @@
expect(tapCount, equals(1));
});
+ testWidgets('Snackbar labels can be colored', (WidgetTester tester) async {
+ await tester.pumpWidget(
+ MaterialApp(
+ home: Scaffold(
+ body: Builder(
+ builder: (BuildContext context) {
+ return GestureDetector(
+ onTap: () {
+ Scaffold.of(context).showSnackBar(
+ SnackBar(
+ content: const Text('I am a snack bar.'),
+ duration: const Duration(seconds: 2),
+ action: SnackBarAction(
+ textColor: Colors.lightBlue,
+ disabledTextColor: Colors.red,
+ label: 'ACTION',
+ onPressed: () {},
+ ),
+ ),
+ );
+ },
+ child: const Text('X')
+ );
+ }
+ ),
+ ),
+ ),
+ );
+
+ await tester.tap(find.text('X'));
+ await tester.pump(); // start animation
+ await tester.pump(const Duration(milliseconds: 750));
+
+ final Element actionTextBox = tester.element(find.text('ACTION'));
+ final Widget textWidget = actionTextBox.widget;
+ final DefaultTextStyle defaultTextStyle = DefaultTextStyle.of(actionTextBox);
+ if (textWidget is Text) {
+ TextStyle effectiveStyle = textWidget.style;
+ effectiveStyle = defaultTextStyle.style.merge(textWidget.style);
+ expect(effectiveStyle.color, Colors.lightBlue);
+ } else
+ expect(false, true);
+ });
+
testWidgets('SnackBar button text alignment', (WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(
home: MediaQuery(