diff --git a/examples/stocks/flutter.yaml b/examples/stocks/flutter.yaml index bbbe0956af..fa953d6236 100644 --- a/examples/stocks/flutter.yaml +++ b/examples/stocks/flutter.yaml @@ -12,6 +12,7 @@ material-design-icons: - name: action/thumb_up - name: content/add - name: device/dvr + - name: editor/border_clear - name: navigation/arrow_back - name: navigation/menu - name: navigation/more_vert diff --git a/examples/stocks/lib/main.dart b/examples/stocks/lib/main.dart index 11cf5b9625..b0d7042607 100644 --- a/examples/stocks/lib/main.dart +++ b/examples/stocks/lib/main.dart @@ -48,17 +48,20 @@ class StocksAppState extends State { StockMode _optimismSetting = StockMode.optimistic; BackupMode _backupSetting = BackupMode.disabled; + bool _showGridSetting = false; void modeUpdater(StockMode optimism) { setState(() { _optimismSetting = optimism; }); } - void settingsUpdater({ StockMode optimism, BackupMode backup }) { + void settingsUpdater({ StockMode optimism, BackupMode backup, bool showGrid }) { setState(() { if (optimism != null) _optimismSetting = optimism; if (backup != null) _backupSetting = backup; + if (showGrid != null) + _showGridSetting = showGrid; }); } @@ -105,9 +108,10 @@ class StocksAppState extends State { return new MaterialApp( title: 'Stocks', theme: theme, + debugShowMaterialGrid: _showGridSetting, routes: { '/': (RouteArguments args) => new StockHome(_stocks, _symbols, _optimismSetting, modeUpdater), - '/settings': (RouteArguments args) => new StockSettings(_optimismSetting, _backupSetting, settingsUpdater) + '/settings': (RouteArguments args) => new StockSettings(_optimismSetting, _backupSetting, _showGridSetting, settingsUpdater) }, onGenerateRoute: _getRoute, onLocaleChanged: _onLocaleChanged diff --git a/examples/stocks/lib/stock_settings.dart b/examples/stocks/lib/stock_settings.dart index 1fe46e5009..c58a5db045 100644 --- a/examples/stocks/lib/stock_settings.dart +++ b/examples/stocks/lib/stock_settings.dart @@ -6,15 +6,17 @@ part of stocks; typedef void SettingsUpdater({ StockMode optimism, - BackupMode backup + BackupMode backup, + bool showGrid }); class StockSettings extends StatefulComponent { - const StockSettings(this.optimism, this.backup, this.updater); + const StockSettings(this.optimism, this.backup, this.showGrid, this.updater); final StockMode optimism; final BackupMode backup; final SettingsUpdater updater; + final bool showGrid; StockSettingsState createState() => new StockSettingsState(); } @@ -22,11 +24,15 @@ class StockSettings extends StatefulComponent { class StockSettingsState extends State { void _handleOptimismChanged(bool value) { value ??= false; - sendUpdates(value ? StockMode.optimistic : StockMode.pessimistic, config.backup); + sendUpdates(value ? StockMode.optimistic : StockMode.pessimistic, config.backup, config.showGrid); } void _handleBackupChanged(bool value) { - sendUpdates(config.optimism, value ? BackupMode.enabled : BackupMode.disabled); + sendUpdates(config.optimism, value ? BackupMode.enabled : BackupMode.disabled, config.showGrid); + } + + void _handleShowGridChanged(bool value) { + sendUpdates(config.optimism, config.backup, value); } void _confirmOptimismChange() { @@ -60,11 +66,12 @@ class StockSettingsState extends State { } } - void sendUpdates(StockMode optimism, BackupMode backup) { + void sendUpdates(StockMode optimism, BackupMode backup, bool showGrid) { if (config.updater != null) config.updater( optimism: optimism, - backup: backup + backup: backup, + showGrid: showGrid ); } @@ -77,30 +84,49 @@ class StockSettingsState extends State { Widget buildSettingsPane(BuildContext context) { // TODO(ianh): Once we have the gesture API hooked up, fix https://github.com/domokit/mojo/issues/281 // (whereby tapping the widgets below causes both the widget and the menu item to fire their callbacks) - return new Block([ + List rows = [ + new DrawerItem( + icon: 'action/thumb_up', + onPressed: () => _confirmOptimismChange(), + child: new Row([ + new Flexible(child: new Text('Everything is awesome')), + new Checkbox( + value: config.optimism == StockMode.optimistic, + onChanged: (bool value) => _confirmOptimismChange() + ), + ]) + ), + new DrawerItem( + icon: 'action/backup', + onPressed: () { _handleBackupChanged(!(config.backup == BackupMode.enabled)); }, + child: new Row([ + new Flexible(child: new Text('Back up stock list to the cloud')), + new Switch( + value: config.backup == BackupMode.enabled, + onChanged: _handleBackupChanged + ), + ]) + ), + ]; + assert(() { + // material grid is only available in checked mode + rows.add( new DrawerItem( - icon: 'action/thumb_up', - onPressed: () => _confirmOptimismChange(), + icon: 'editor/border_clear', + onPressed: () { _handleShowGridChanged(!config.showGrid); }, child: new Row([ - new Flexible(child: new Text('Everything is awesome')), - new Checkbox( - value: config.optimism == StockMode.optimistic, - onChanged: (bool value) => _confirmOptimismChange() - ), - ]) - ), - new DrawerItem( - icon: 'action/backup', - onPressed: () { _handleBackupChanged(!(config.backup == BackupMode.enabled)); }, - child: new Row([ - new Flexible(child: new Text('Back up stock list to the cloud')), + new Flexible(child: new Text('Show material grid (for debugging)')), new Switch( - value: config.backup == BackupMode.enabled, - onChanged: _handleBackupChanged + value: config.showGrid, + onChanged: _handleShowGridChanged ), ]) - ), - ], + ) + ); + return true; + }); + return new Block( + rows, padding: const EdgeDims.symmetric(vertical: 20.0) ); } diff --git a/packages/flutter/lib/src/material/material_app.dart b/packages/flutter/lib/src/material/material_app.dart index 128e9cc551..07c846d84a 100644 --- a/packages/flutter/lib/src/material/material_app.dart +++ b/packages/flutter/lib/src/material/material_app.dart @@ -47,10 +47,12 @@ class MaterialApp extends StatefulComponent { this.theme, this.routes: const {}, this.onGenerateRoute, - this.onLocaleChanged + this.onLocaleChanged, + this.debugShowMaterialGrid: false }) : super(key: key) { assert(routes != null); assert(routes.containsKey(Navigator.defaultRouteName) || onGenerateRoute != null); + assert(debugShowMaterialGrid != null); } final String title; @@ -58,6 +60,7 @@ class MaterialApp extends StatefulComponent { final Map routes; final RouteFactory onGenerateRoute; final LocaleChangedCallback onLocaleChanged; + final bool debugShowMaterialGrid; _MaterialAppState createState() => new _MaterialAppState(); } @@ -131,7 +134,7 @@ class _MaterialAppState extends State implements BindingObserver { } ThemeData theme = config.theme ?? new ThemeData.fallback(); - return new MediaQuery( + Widget result = new MediaQuery( data: new MediaQueryData(size: _size), child: new LocaleQuery( data: _localeData, @@ -156,6 +159,19 @@ class _MaterialAppState extends State implements BindingObserver { ) ) ); + assert(() { + if (config.debugShowMaterialGrid) { + result = new GridPaper( + color: const Color(0xE0F9BBE0), + interval: 8.0, + divisions: 2, + subDivisions: 1, + child: result + ); + } + return true; + }); + return result; } }