Fix the padding and space for FlatButton and RaisedButton (#3650)

Instead of incorporating the margin into the button, introduce a ButtonBar
widget that supplies the proper spacing between the buttons. Also, make these
buttons more configurable via ButtonTheme so that dialogs can change the
minWidth and padding of the buttons as required by the spec.

Fixes #1843
Fixes #3184
This commit is contained in:
Adam Barth
2016-04-29 16:13:25 -07:00
parent f8d76d1851
commit b2fa6c250a
18 changed files with 331 additions and 173 deletions

View File

@@ -96,8 +96,8 @@ class _ButtonsDemoState extends State<ButtonsDemo> {
Widget buildRaisedButton() {
return new Align(
alignment: new FractionalOffset(0.5, 0.4),
child: new Row(
mainAxisAlignment: MainAxisAlignment.collapse,
child: new ButtonBar(
alignment: MainAxisAlignment.collapse,
children: <Widget>[
new RaisedButton(
child: new Text('RAISED BUTTON'),
@@ -116,8 +116,8 @@ class _ButtonsDemoState extends State<ButtonsDemo> {
Widget buildFlatButton() {
return new Align(
alignment: new FractionalOffset(0.5, 0.4),
child: new Row(
mainAxisAlignment: MainAxisAlignment.collapse,
child: new ButtonBar(
alignment: MainAxisAlignment.collapse,
children: <Widget>[
new FlatButton(
child: new Text('FLAT BUTTON'),

View File

@@ -44,18 +44,17 @@ class TravelDestinationItem extends StatelessWidget {
static final double height = 328.0;
final TravelDestination destination;
@override
Widget build(BuildContext context) {
ThemeData theme = Theme.of(context);
TextStyle titleStyle = theme.textTheme.headline.copyWith(color: Colors.white);
TextStyle descriptionStyle = theme.textTheme.subhead;
TextStyle buttonStyle = theme.textTheme.button.copyWith(color: theme.primaryColor);
return new SizedBox(
height: height,
child: new Card(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
// photo and title
new SizedBox(
@@ -83,33 +82,35 @@ class TravelDestinationItem extends StatelessWidget {
// description and share/expore buttons
new Flexible(
child: new Padding(
padding: const EdgeInsets.all(16.0),
padding: const EdgeInsets.fromLTRB(16.0, 16.0, 16.0, 0.0),
child: new Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
// three line description
new Text(destination.description[0], style: descriptionStyle),
new Text(destination.description[1], style: descriptionStyle),
new Text(destination.description[2], style: descriptionStyle),
// share, explore buttons
new Flexible(
child: new Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
new Padding(
padding: const EdgeInsets.only(right: 16.0),
child: new Text('SHARE', style: buttonStyle)
),
new Text('EXPLORE', style: buttonStyle)
]
)
)
]
)
)
)
),
// share, explore buttons
// TODO(abarth): The theme and the bar should be part of card.
new ButtonTheme.footer(
child: new ButtonBar(
alignment: MainAxisAlignment.start,
children: <Widget>[
new FlatButton(
child: new Text('SHARE'),
onPressed: () { /* do nothing */ }
),
new FlatButton(
child: new Text('EXPLORE'),
onPressed: () { /* do nothing */ }
),
]
)
),
]
)
)

View File

@@ -39,6 +39,7 @@ class _DatePickerDemoState extends State<DatePickerDemo> {
body: new Column(
children: <Widget>[
new Text(new DateFormat.yMMMd().format(_selectedDate)),
new SizedBox(height: 20.0),
new RaisedButton(
onPressed: _handleSelectDate,
child: new Text('SELECT DATE')

View File

@@ -33,14 +33,15 @@ class _TimePickerDemoState extends State<TimePickerDemo> {
return new Scaffold(
appBar: new AppBar(title: new Text('Time picker')),
body: new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Text('$_selectedTime'),
new SizedBox(height: 20.0),
new RaisedButton(
onPressed: _handleSelectTime,
child: new Text('SELECT TIME')
),
],
mainAxisAlignment: MainAxisAlignment.center
]
)
);
}