OLD | NEW |
---|---|
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/editing/input.dart'; | 5 import 'package:sky/editing/input.dart'; |
6 import 'package:sky/theme/colors.dart' as colors; | 6 import 'package:sky/theme/colors.dart' as colors; |
7 import 'package:sky/theme/typography.dart' as typography; | 7 import 'package:sky/theme/typography.dart' as typography; |
8 import 'package:sky/widgets/basic.dart'; | 8 import 'package:sky/widgets/basic.dart'; |
9 import 'package:sky/widgets/drawer.dart'; | 9 import 'package:sky/widgets/drawer.dart'; |
10 import 'package:sky/widgets/drawer_header.dart'; | 10 import 'package:sky/widgets/drawer_header.dart'; |
(...skipping 11 matching lines...) Expand all Loading... | |
22 import 'package:sky/widgets/widget.dart'; | 22 import 'package:sky/widgets/widget.dart'; |
23 | 23 |
24 import 'stock_data.dart'; | 24 import 'stock_data.dart'; |
25 import 'stock_list.dart'; | 25 import 'stock_list.dart'; |
26 import 'stock_menu.dart'; | 26 import 'stock_menu.dart'; |
27 | 27 |
28 enum StockMode { optimistic, pessimistic } | 28 enum StockMode { optimistic, pessimistic } |
29 | 29 |
30 class StockHome extends Component { | 30 class StockHome extends Component { |
31 | 31 |
32 StockHome(this._navigator) { | 32 StockHome(this.navigator, RouteBase route, this.stocks) : super(stateful: true ) { |
33 // if (debug) | 33 // if (debug) |
34 // new Timer(new Duration(seconds: 1), dumpState); | 34 // new Timer(new Duration(seconds: 1), dumpState); |
35 new StockDataFetcher((StockData data) { | |
36 setState(() { | |
37 data.appendTo(_stocks); | |
38 }); | |
39 }); | |
40 _drawerController = new DrawerController(_handleDrawerStatusChanged); | 35 _drawerController = new DrawerController(_handleDrawerStatusChanged); |
41 } | 36 } |
42 | 37 |
43 List<Stock> _stocks = []; | 38 void syncFields(StockHome source) { |
44 Navigator _navigator; | 39 navigator = source.navigator; |
40 stocks = source.stocks; | |
41 } | |
42 | |
43 Navigator navigator; | |
44 List<Stock> stocks; | |
45 | 45 |
46 bool _isSearching = false; | 46 bool _isSearching = false; |
47 String _searchQuery; | 47 String _searchQuery; |
48 | 48 |
49 void _handleSearchBegin() { | 49 void _handleSearchBegin() { |
50 setState(() { | 50 setState(() { |
51 _isSearching = true; | 51 _isSearching = true; |
52 }); | 52 }); |
53 } | 53 } |
54 | 54 |
55 void _handleSearchEnd() { | 55 void _handleSearchEnd() { |
56 setState(() { | 56 setState(() { |
57 _isSearching = false; | 57 _isSearching = false; |
58 _searchQuery = null; | 58 _searchQuery = null; |
59 }); | 59 }); |
60 } | 60 } |
61 | 61 |
62 void _handleSearchQueryChanged(String query) { | 62 void _handleSearchQueryChanged(String query) { |
63 setState(() { | 63 setState(() { |
64 _searchQuery = query; | 64 _searchQuery = query; |
65 }); | 65 }); |
66 } | 66 } |
67 | 67 |
68 DrawerController _drawerController; | 68 DrawerController _drawerController; |
69 bool _drawerShowing = false; | 69 bool _drawerShowing = false; |
70 | 70 |
71 void _handleDrawerStatusChanged(bool showing) { | 71 void _handleDrawerStatusChanged(bool showing) { |
72 if (!showing && navigator.currentRoute.name == "/drawer") { | |
73 navigator.pop(); | |
74 } | |
72 setState(() { | 75 setState(() { |
73 _drawerShowing = showing; | 76 _drawerShowing = showing; |
74 }); | 77 }); |
75 } | 78 } |
76 | 79 |
77 PopupMenuController _menuController; | 80 PopupMenuController _menuController; |
78 | 81 |
79 void _handleMenuShow() { | 82 void _handleMenuShow() { |
80 setState(() { | 83 setState(() { |
81 _menuController = new PopupMenuController(); | 84 _menuController = new PopupMenuController(); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 new MenuItem( | 133 new MenuItem( |
131 icon: 'action/thumb_down', | 134 icon: 'action/thumb_down', |
132 onPressed: () => _handleStockModeChange(StockMode.pessimistic), | 135 onPressed: () => _handleStockModeChange(StockMode.pessimistic), |
133 children: [ | 136 children: [ |
134 new Flexible(child: new Text('Pessimistic')), | 137 new Flexible(child: new Text('Pessimistic')), |
135 new Radio(value: StockMode.pessimistic, groupValue: _stockMode, onCh anged: _handleStockModeChange) | 138 new Radio(value: StockMode.pessimistic, groupValue: _stockMode, onCh anged: _handleStockModeChange) |
136 ]), | 139 ]), |
137 new MenuDivider(), | 140 new MenuDivider(), |
138 new MenuItem( | 141 new MenuItem( |
139 icon: 'action/settings', | 142 icon: 'action/settings', |
140 onPressed: () => _navigator.pushNamed('/settings'), | 143 onPressed: () => navigator.pushNamed('/settings'), |
141 children: [new Text('Settings')]), | 144 children: [new Text('Settings')]), |
142 new MenuItem( | 145 new MenuItem( |
143 icon: 'action/help', | 146 icon: 'action/help', |
144 children: [new Text('Help & Feedback')]) | 147 children: [new Text('Help & Feedback')]) |
145 ] | 148 ] |
146 ); | 149 ); |
147 } | 150 } |
148 | 151 |
152 void _handleOpenDrawer() { | |
153 _drawerController.open(); | |
154 navigator.pushState("/drawer", (route) { | |
abarth-chromium
2015/06/18 22:23:59
If you ignore arguments, the convention is to use
| |
155 _drawerController.close(); | |
156 }); | |
157 } | |
158 | |
149 Widget buildToolBar() { | 159 Widget buildToolBar() { |
150 return new ToolBar( | 160 return new ToolBar( |
151 left: new IconButton( | 161 left: new IconButton( |
152 icon: 'navigation/menu_white', | 162 icon: 'navigation/menu_white', |
153 onPressed: _drawerController.toggle), | 163 onPressed: _handleOpenDrawer), |
154 center: new Text('Stocks', style: typography.white.title), | 164 center: new Text('Stocks', style: typography.white.title), |
155 right: [ | 165 right: [ |
156 new IconButton( | 166 new IconButton( |
157 icon: 'action/search_white', | 167 icon: 'action/search_white', |
158 onPressed: _handleSearchBegin), | 168 onPressed: _handleSearchBegin), |
159 new IconButton( | 169 new IconButton( |
160 icon: 'navigation/more_vert_white', | 170 icon: 'navigation/more_vert_white', |
161 onPressed: _handleMenuShow) | 171 onPressed: _handleMenuShow) |
162 ], | 172 ], |
163 backgroundColor: colors.Purple[500] | 173 backgroundColor: colors.Purple[500] |
(...skipping 23 matching lines...) Expand all Loading... | |
187 autorefresh: _autorefresh, | 197 autorefresh: _autorefresh, |
188 onAutorefreshChanged: _handleAutorefreshChanged | 198 onAutorefreshChanged: _handleAutorefreshChanged |
189 )], | 199 )], |
190 onDismiss: _handleMenuHide)); | 200 onDismiss: _handleMenuHide)); |
191 } | 201 } |
192 | 202 |
193 Widget build() { | 203 Widget build() { |
194 List<Widget> overlays = [ | 204 List<Widget> overlays = [ |
195 new Scaffold( | 205 new Scaffold( |
196 toolbar: _isSearching ? buildSearchBar() : buildToolBar(), | 206 toolbar: _isSearching ? buildSearchBar() : buildToolBar(), |
197 body: new Stocklist(stocks: _stocks, query: _searchQuery), | 207 body: new Stocklist(stocks: stocks, query: _searchQuery), |
198 floatingActionButton: new FloatingActionButton( | 208 floatingActionButton: new FloatingActionButton( |
199 child: new Icon(type: 'content/add_white', size: 24) | 209 child: new Icon(type: 'content/add_white', size: 24) |
200 ), | 210 ), |
201 drawer: _drawerShowing ? buildDrawer() : null | 211 drawer: _drawerShowing ? buildDrawer() : null |
202 ), | 212 ), |
203 ]; | 213 ]; |
204 addMenuToOverlays(overlays); | 214 addMenuToOverlays(overlays); |
205 return new Stack(overlays); | 215 return new Stack(overlays); |
206 } | 216 } |
207 } | 217 } |
OLD | NEW |