parent
b715cf142d
commit
bc56a7a6c5
@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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(
|
||||
|
Loading…
x
Reference in New Issue
Block a user