Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1272)

Side by Side Diff: sky/examples/stocks2/lib/stock_settings.dart

Issue 1197333002: Make the checkbox in settings control the radio buttons in the drawer, to demonstrate how to link s… (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/examples/stocks2/lib/stock_home.dart ('k') | sky/examples/stocks2/lib/stock_types.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 import 'package:sky/theme/colors.dart' as colors; 5 import 'package:sky/theme/colors.dart' as colors;
6 import 'package:sky/widgets/basic.dart'; 6 import 'package:sky/widgets/basic.dart';
7 import 'package:sky/widgets/checkbox.dart'; 7 import 'package:sky/widgets/checkbox.dart';
8 import 'package:sky/widgets/icon_button.dart'; 8 import 'package:sky/widgets/icon_button.dart';
9 import 'package:sky/widgets/menu_item.dart'; 9 import 'package:sky/widgets/menu_item.dart';
10 import 'package:sky/widgets/navigator.dart'; 10 import 'package:sky/widgets/navigator.dart';
11 import 'package:sky/widgets/scaffold.dart'; 11 import 'package:sky/widgets/scaffold.dart';
12 import 'package:sky/widgets/theme.dart'; 12 import 'package:sky/widgets/theme.dart';
13 import 'package:sky/widgets/tool_bar.dart'; 13 import 'package:sky/widgets/tool_bar.dart';
14 14
15 import 'stock_types.dart';
16
17 typedef void SettingsUpdater({StockMode mode});
18
15 class StockSettings extends Component { 19 class StockSettings extends Component {
16 20
17 StockSettings(this._navigator); 21 StockSettings(this.navigator, this.stockMode, this.updater) : super(stateful: true);
18 22
19 Navigator _navigator; 23 Navigator navigator;
24 StockMode stockMode;
25 SettingsUpdater updater;
20 26
21 bool _awesome = false; 27 void syncFields(StockSettings source) {
22 void _handleAwesomeChanged(bool value) { 28 navigator = source.navigator;
29 stockMode = source.stockMode;
30 updater = source.updater;
31 }
32
33 void _handleStockModeChanged(bool value) {
23 setState(() { 34 setState(() {
24 _awesome = value; 35 stockMode = value ? StockMode.optimistic : StockMode.pessimistic;
25 }); 36 });
37 sendUpdates();
38 }
39
40 void sendUpdates() {
41 if (updater != null)
42 updater(
43 mode: stockMode
44 );
26 } 45 }
27 46
28 Widget buildToolBar() { 47 Widget buildToolBar() {
29 return new ToolBar( 48 return new ToolBar(
30 left: new IconButton( 49 left: new IconButton(
31 icon: 'navigation/arrow_back_white', 50 icon: 'navigation/arrow_back_white',
32 onPressed: _navigator.pop), 51 onPressed: navigator.pop),
33 center: new Text('Settings', style: Theme.of(this).text.title) 52 center: new Text('Settings', style: Theme.of(this).text.title)
34 ); 53 );
35 } 54 }
36 55
37 Widget buildSettingsPane() { 56 Widget buildSettingsPane() {
38 return new Container( 57 return new Container(
39 padding: const EdgeDims.symmetric(vertical: 20.0), 58 padding: const EdgeDims.symmetric(vertical: 20.0),
40 decoration: new BoxDecoration(backgroundColor: colors.Grey[50]), 59 decoration: new BoxDecoration(backgroundColor: colors.Grey[50]),
41 child: new Block([ 60 child: new Block([
42 new MenuItem( 61 new MenuItem(
43 icon: 'action/thumb_up', 62 icon: 'action/thumb_up',
44 onPressed: () => _handleAwesomeChanged(!_awesome), 63 onPressed: () => _handleStockModeChanged(stockMode == StockMode.optimi stic ? false : true),
45 children: [ 64 children: [
46 new Flexible(child: new Text('Everything is awesome')), 65 new Flexible(child: new Text('Everything is awesome')),
47 new Checkbox(value: _awesome, onChanged: _handleAwesomeChanged) 66 new Checkbox(value: stockMode == StockMode.optimistic, onChanged: _h andleStockModeChanged)
48 ] 67 ]
49 ), 68 ),
50 ]) 69 ])
51 ); 70 );
52 } 71 }
53 72
54 Widget build() { 73 Widget build() {
55 return new Scaffold( 74 return new Scaffold(
56 toolbar: buildToolBar(), 75 toolbar: buildToolBar(),
57 body: buildSettingsPane() 76 body: buildSettingsPane()
58 ); 77 );
59 } 78 }
60 } 79 }
OLDNEW
« no previous file with comments | « sky/examples/stocks2/lib/stock_home.dart ('k') | sky/examples/stocks2/lib/stock_types.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698