Commit d9d3114d authored by Ian Hickson's avatar Ian Hickson
parent 99112425
...@@ -12,6 +12,7 @@ material-design-icons: ...@@ -12,6 +12,7 @@ material-design-icons:
- name: action/thumb_up - name: action/thumb_up
- name: content/add - name: content/add
- name: device/dvr - name: device/dvr
- name: editor/border_clear
- name: navigation/arrow_back - name: navigation/arrow_back
- name: navigation/menu - name: navigation/menu
- name: navigation/more_vert - name: navigation/more_vert
...@@ -48,17 +48,20 @@ class StocksAppState extends State<StocksApp> { ...@@ -48,17 +48,20 @@ class StocksAppState extends State<StocksApp> {
StockMode _optimismSetting = StockMode.optimistic; StockMode _optimismSetting = StockMode.optimistic;
BackupMode _backupSetting = BackupMode.disabled; BackupMode _backupSetting = BackupMode.disabled;
bool _showGridSetting = false;
void modeUpdater(StockMode optimism) { void modeUpdater(StockMode optimism) {
setState(() { setState(() {
_optimismSetting = optimism; _optimismSetting = optimism;
}); });
} }
void settingsUpdater({ StockMode optimism, BackupMode backup }) { void settingsUpdater({ StockMode optimism, BackupMode backup, bool showGrid }) {
setState(() { setState(() {
if (optimism != null) if (optimism != null)
_optimismSetting = optimism; _optimismSetting = optimism;
if (backup != null) if (backup != null)
_backupSetting = backup; _backupSetting = backup;
if (showGrid != null)
_showGridSetting = showGrid;
}); });
} }
...@@ -105,9 +108,10 @@ class StocksAppState extends State<StocksApp> { ...@@ -105,9 +108,10 @@ class StocksAppState extends State<StocksApp> {
return new MaterialApp( return new MaterialApp(
title: 'Stocks', title: 'Stocks',
theme: theme, theme: theme,
debugShowMaterialGrid: _showGridSetting,
routes: <String, RouteBuilder>{ routes: <String, RouteBuilder>{
'/': (RouteArguments args) => new StockHome(_stocks, _symbols, _optimismSetting, modeUpdater), '/': (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, onGenerateRoute: _getRoute,
onLocaleChanged: _onLocaleChanged onLocaleChanged: _onLocaleChanged
......
...@@ -6,15 +6,17 @@ part of stocks; ...@@ -6,15 +6,17 @@ part of stocks;
typedef void SettingsUpdater({ typedef void SettingsUpdater({
StockMode optimism, StockMode optimism,
BackupMode backup BackupMode backup,
bool showGrid
}); });
class StockSettings extends StatefulComponent { 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 StockMode optimism;
final BackupMode backup; final BackupMode backup;
final SettingsUpdater updater; final SettingsUpdater updater;
final bool showGrid;
StockSettingsState createState() => new StockSettingsState(); StockSettingsState createState() => new StockSettingsState();
} }
...@@ -22,11 +24,15 @@ class StockSettings extends StatefulComponent { ...@@ -22,11 +24,15 @@ class StockSettings extends StatefulComponent {
class StockSettingsState extends State<StockSettings> { class StockSettingsState extends State<StockSettings> {
void _handleOptimismChanged(bool value) { void _handleOptimismChanged(bool value) {
value ??= false; value ??= false;
sendUpdates(value ? StockMode.optimistic : StockMode.pessimistic, config.backup); sendUpdates(value ? StockMode.optimistic : StockMode.pessimistic, config.backup, config.showGrid);
} }
void _handleBackupChanged(bool value) { 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() { void _confirmOptimismChange() {
...@@ -60,11 +66,12 @@ class StockSettingsState extends State<StockSettings> { ...@@ -60,11 +66,12 @@ class StockSettingsState extends State<StockSettings> {
} }
} }
void sendUpdates(StockMode optimism, BackupMode backup) { void sendUpdates(StockMode optimism, BackupMode backup, bool showGrid) {
if (config.updater != null) if (config.updater != null)
config.updater( config.updater(
optimism: optimism, optimism: optimism,
backup: backup backup: backup,
showGrid: showGrid
); );
} }
...@@ -77,30 +84,49 @@ class StockSettingsState extends State<StockSettings> { ...@@ -77,30 +84,49 @@ class StockSettingsState extends State<StockSettings> {
Widget buildSettingsPane(BuildContext context) { Widget buildSettingsPane(BuildContext context) {
// TODO(ianh): Once we have the gesture API hooked up, fix https://github.com/domokit/mojo/issues/281 // 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) // (whereby tapping the widgets below causes both the widget and the menu item to fire their callbacks)
return new Block(<Widget>[ List<Widget> rows = <Widget>[
new DrawerItem(
icon: 'action/thumb_up',
onPressed: () => _confirmOptimismChange(),
child: new Row(<Widget>[
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(<Widget>[
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( new DrawerItem(
icon: 'action/thumb_up', icon: 'editor/border_clear',
onPressed: () => _confirmOptimismChange(), onPressed: () { _handleShowGridChanged(!config.showGrid); },
child: new Row(<Widget>[ child: new Row(<Widget>[
new Flexible(child: new Text('Everything is awesome')), new Flexible(child: new Text('Show material grid (for debugging)')),
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(<Widget>[
new Flexible(child: new Text('Back up stock list to the cloud')),
new Switch( new Switch(
value: config.backup == BackupMode.enabled, value: config.showGrid,
onChanged: _handleBackupChanged onChanged: _handleShowGridChanged
), ),
]) ])
), )
], );
return true;
});
return new Block(
rows,
padding: const EdgeDims.symmetric(vertical: 20.0) padding: const EdgeDims.symmetric(vertical: 20.0)
); );
} }
......
...@@ -47,10 +47,12 @@ class MaterialApp extends StatefulComponent { ...@@ -47,10 +47,12 @@ class MaterialApp extends StatefulComponent {
this.theme, this.theme,
this.routes: const <String, RouteBuilder>{}, this.routes: const <String, RouteBuilder>{},
this.onGenerateRoute, this.onGenerateRoute,
this.onLocaleChanged this.onLocaleChanged,
this.debugShowMaterialGrid: false
}) : super(key: key) { }) : super(key: key) {
assert(routes != null); assert(routes != null);
assert(routes.containsKey(Navigator.defaultRouteName) || onGenerateRoute != null); assert(routes.containsKey(Navigator.defaultRouteName) || onGenerateRoute != null);
assert(debugShowMaterialGrid != null);
} }
final String title; final String title;
...@@ -58,6 +60,7 @@ class MaterialApp extends StatefulComponent { ...@@ -58,6 +60,7 @@ class MaterialApp extends StatefulComponent {
final Map<String, RouteBuilder> routes; final Map<String, RouteBuilder> routes;
final RouteFactory onGenerateRoute; final RouteFactory onGenerateRoute;
final LocaleChangedCallback onLocaleChanged; final LocaleChangedCallback onLocaleChanged;
final bool debugShowMaterialGrid;
_MaterialAppState createState() => new _MaterialAppState(); _MaterialAppState createState() => new _MaterialAppState();
} }
...@@ -131,7 +134,7 @@ class _MaterialAppState extends State<MaterialApp> implements BindingObserver { ...@@ -131,7 +134,7 @@ class _MaterialAppState extends State<MaterialApp> implements BindingObserver {
} }
ThemeData theme = config.theme ?? new ThemeData.fallback(); ThemeData theme = config.theme ?? new ThemeData.fallback();
return new MediaQuery( Widget result = new MediaQuery(
data: new MediaQueryData(size: _size), data: new MediaQueryData(size: _size),
child: new LocaleQuery( child: new LocaleQuery(
data: _localeData, data: _localeData,
...@@ -156,6 +159,19 @@ class _MaterialAppState extends State<MaterialApp> implements BindingObserver { ...@@ -156,6 +159,19 @@ class _MaterialAppState extends State<MaterialApp> 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;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment