mirror of
https://github.com/flutter/samples.git
synced 2025-11-08 13:58:47 +00:00
Migrate to the New Material Buttons (#668)
This commit is contained in:
@@ -83,12 +83,12 @@ class _CartTotal extends StatelessWidget {
|
||||
builder: (context, cart, child) =>
|
||||
Text('\$${cart.totalPrice}', style: hugeStyle)),
|
||||
SizedBox(width: 24),
|
||||
FlatButton(
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Scaffold.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Buying not supported yet.')));
|
||||
},
|
||||
color: Colors.white,
|
||||
style: TextButton.styleFrom(primary: Colors.white),
|
||||
child: Text('BUY'),
|
||||
),
|
||||
],
|
||||
|
||||
@@ -43,7 +43,7 @@ class _AddButton extends StatelessWidget {
|
||||
(cart) => cart.items.contains(item),
|
||||
);
|
||||
|
||||
return FlatButton(
|
||||
return TextButton(
|
||||
onPressed: isInCart
|
||||
? null
|
||||
: () {
|
||||
@@ -54,7 +54,14 @@ class _AddButton extends StatelessWidget {
|
||||
var cart = context.read<CartModel>();
|
||||
cart.add(item);
|
||||
},
|
||||
splashColor: Theme.of(context).primaryColor,
|
||||
style: ButtonStyle(
|
||||
overlayColor: MaterialStateProperty.resolveWith<Color>((states) {
|
||||
if (states.contains(MaterialState.pressed)) {
|
||||
return Theme.of(context).primaryColor;
|
||||
}
|
||||
return null; // Defer to the widget's default.
|
||||
}),
|
||||
),
|
||||
child: isInCart ? Icon(Icons.check, semanticLabel: 'ADDED') : Text('ADD'),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -32,12 +32,14 @@ class MyLogin extends StatelessWidget {
|
||||
SizedBox(
|
||||
height: 24,
|
||||
),
|
||||
RaisedButton(
|
||||
color: Colors.yellow,
|
||||
ElevatedButton(
|
||||
child: Text('ENTER'),
|
||||
onPressed: () {
|
||||
Navigator.pushReplacementNamed(context, '/catalog');
|
||||
},
|
||||
style: ElevatedButton.styleFrom(
|
||||
primary: Colors.yellow,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
|
||||
@@ -48,7 +48,7 @@ void main() {
|
||||
expect(find.text('ADD'), findsWidgets);
|
||||
|
||||
// Performing the click on the ADD button of the first item in the list.
|
||||
await tester.tap(find.widgetWithText(FlatButton, 'ADD').first);
|
||||
await tester.tap(find.widgetWithText(TextButton, 'ADD').first);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Verifying if the tapped ADD button has changed to the check icon.
|
||||
|
||||
Reference in New Issue
Block a user