Snack color (#23255)

* added test
This commit is contained in:
jslavitz 2018-10-25 10:56:59 -07:00 committed by GitHub
parent b715cf142d
commit bc56a7a6c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 55 additions and 0 deletions

View File

@ -81,12 +81,21 @@ class SnackBarAction extends StatefulWidget {
/// 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 @@ class _SnackBarActionState extends State<SnackBarAction> {
return FlatButton(
onPressed: _haveTriggeredAction ? null : _handlePressed,
child: Text(widget.label),
textColor: widget.textColor,
disabledTextColor: widget.disabledTextColor,
);
}
}

View File

@ -296,6 +296,50 @@ void main() {
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(