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

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

Issue 1218593002: Move sky/examples to sky/sdk/lib/example, and code changes to support that change. Fixes T277. (Closed) Base URL: git@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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 import 'package:sky/theme/colors.dart' as colors;
6 import 'package:sky/widgets/basic.dart';
7 import 'package:sky/widgets/checkbox.dart';
8 import 'package:sky/widgets/flat_button.dart';
9 import 'package:sky/widgets/dialog.dart';
10 import 'package:sky/widgets/icon_button.dart';
11 import 'package:sky/widgets/menu_item.dart';
12 import 'package:sky/widgets/navigator.dart';
13 import 'package:sky/widgets/scaffold.dart';
14 import 'package:sky/widgets/tool_bar.dart';
15
16 import 'stock_types.dart';
17
18 typedef void SettingsUpdater({StockMode mode});
19
20 class StockSettings extends Component {
21
22 StockSettings(this.navigator, this.stockMode, this.updater) : super(stateful: true);
23
24 Navigator navigator;
25 StockMode stockMode;
26 SettingsUpdater updater;
27 bool showModeDialog = false;
28
29 void syncFields(StockSettings source) {
30 navigator = source.navigator;
31 stockMode = source.stockMode;
32 updater = source.updater;
33 }
34
35 void _handleStockModeChanged(bool value) {
36 setState(() {
37 stockMode = value ? StockMode.optimistic : StockMode.pessimistic;
38 });
39 sendUpdates();
40 }
41
42 void _confirmStockModeChange() {
43 switch (stockMode) {
44 case StockMode.optimistic:
45 _handleStockModeChanged(false);
46 break;
47 case StockMode.pessimistic:
48 showModeDialog = true;
49 navigator.pushState("/settings/confirm", (_) {
50 showModeDialog = false;
51 });
52 break;
53 }
54 }
55
56 void sendUpdates() {
57 if (updater != null)
58 updater(
59 mode: stockMode
60 );
61 }
62
63 Widget buildToolBar() {
64 return new ToolBar(
65 left: new IconButton(
66 icon: 'navigation/arrow_back_white',
67 onPressed: navigator.pop),
68 center: new Text('Settings')
69 );
70 }
71
72 Widget buildSettingsPane() {
73 return new Container(
74 padding: const EdgeDims.symmetric(vertical: 20.0),
75 decoration: new BoxDecoration(backgroundColor: colors.Grey[50]),
76 child: new Block([
77 new MenuItem(
78 icon: 'action/thumb_up',
79 onPressed: () => _confirmStockModeChange(),
80 children: [
81 new Flexible(child: new Text('Everything is awesome')),
82 new Checkbox(value: stockMode == StockMode.optimistic, onChanged: _h andleStockModeChanged)
83 ]
84 ),
85 ])
86 );
87 }
88
89 Widget build() {
90 List<Widget> layers = [new Scaffold(
91 toolbar: buildToolBar(),
92 body: buildSettingsPane()
93 )];
94 if (showModeDialog) {
95 layers.add(new Dialog(
96 title: new Text("Change mode?"),
97 content: new Text("Optimistic mode means everything is awesome. Are you sure you can handle that?"),
98 onDismiss: navigator.pop,
99 actions: [
100 new FlatButton(
101 child: new Text('NO THANKS'),
102 onPressed: navigator.pop
103 ),
104 new FlatButton(
105 child: new Text('AGREE'),
106 onPressed: () {
107 _handleStockModeChanged(true);
108 navigator.pop();
109 }
110 ),
111 ]
112 ));
113 }
114 return new Stack(layers);
115 }
116 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698