diff --git a/examples/flutter_gallery/lib/demo/material/icons_demo.dart b/examples/flutter_gallery/lib/demo/material/icons_demo.dart index 4f0dd36adfb..64c9919a844 100644 --- a/examples/flutter_gallery/lib/demo/material/icons_demo.dart +++ b/examples/flutter_gallery/lib/demo/material/icons_demo.dart @@ -44,29 +44,8 @@ class IconsDemoState extends State { }); } - Widget buildIconButton(double iconSize, IconData icon, bool enabled) { - return new IconButton( - icon: new Icon(icon), - iconSize: iconSize, - tooltip: "${enabled ? 'Enabled' : 'Disabled'} icon button", - onPressed: enabled ? handleIconButtonPress : null - ); - } - - Widget buildSizeLabel(int size, TextStyle style) { - return new SizedBox( - height: size.toDouble() + 16.0, // to match an IconButton's padded height - child: new Center( - child: new Text('$size', style: style) - ) - ); - } - @override Widget build(BuildContext context) { - final ThemeData theme = Theme.of(context); - final TextStyle textStyle = theme.textTheme.subhead.copyWith(color: theme.textTheme.caption.color); - return new Scaffold( appBar: new AppBar( title: const Text('Icons') @@ -77,46 +56,7 @@ class IconsDemoState extends State { padding: const EdgeInsets.all(24.0), child: new Column( children: [ - new Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - new Column( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - new Text('Size', style: textStyle), - buildSizeLabel(18, textStyle), - buildSizeLabel(24, textStyle), - buildSizeLabel(36, textStyle), - buildSizeLabel(48, textStyle), - ], - ), - new Expanded( - child: new Column( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - new Text('Enabled', style: textStyle), - buildIconButton(18.0, Icons.face, true), - buildIconButton(24.0, Icons.alarm, true), - buildIconButton(36.0, Icons.home, true), - buildIconButton(48.0, Icons.android, true), - ], - ) - ), - new Expanded( - child: new Column( - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - new Text('Disabled', style: textStyle), - buildIconButton(18.0, Icons.face, false), - buildIconButton(24.0, Icons.alarm, false), - buildIconButton(36.0, Icons.home, false), - buildIconButton(48.0, Icons.android, false), - ], - ), - ), - ], - ), + new _IconsDemoCard(handleIconButtonPress), ], ), ), @@ -124,3 +64,63 @@ class IconsDemoState extends State { ); } } + +class _IconsDemoCard extends StatelessWidget { + + const _IconsDemoCard(this.handleIconButtonPress); + + final VoidCallback handleIconButtonPress; + + Widget _buildIconButton(double iconSize, IconData icon, bool enabled) { + return new IconButton( + icon: new Icon(icon), + iconSize: iconSize, + tooltip: "${enabled ? 'Enabled' : 'Disabled'} icon button", + onPressed: enabled ? handleIconButtonPress : null + ); + } + + Widget _centeredText(String label) => + new Padding( + // Match the default padding of IconButton. + padding: const EdgeInsets.all(8.0), + child: new Text(label, textAlign: TextAlign.center), + ); + + TableRow _buildIconRow(double size) { + return new TableRow( + children: [ + _centeredText(size.floor().toString()), + _buildIconButton(size, Icons.face, true), + _buildIconButton(size, Icons.face, false), + ], + ); + } + + @override + Widget build(BuildContext context) { + final ThemeData theme = Theme.of(context); + final TextStyle textStyle = theme.textTheme.subhead.copyWith(color: theme.textTheme.caption.color); + return new Card( + child: new DefaultTextStyle( + style: textStyle, + child: new Table( + defaultVerticalAlignment: TableCellVerticalAlignment.middle, + children: [ + new TableRow( + children: [ + _centeredText('Size'), + _centeredText('Enabled'), + _centeredText('Disabled'), + ] + ), + _buildIconRow(18.0), + _buildIconRow(24.0), + _buildIconRow(36.0), + _buildIconRow(48.0), + ], + ), + ), + ); + } +}