| 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/widgets/basic.dart'; | 7 import 'package:sky/widgets/basic.dart'; |
| 8 import 'package:sky/widgets/drawer.dart'; | 8 import 'package:sky/widgets/drawer.dart'; |
| 9 import 'package:sky/widgets/drawer_header.dart'; | 9 import 'package:sky/widgets/drawer_header.dart'; |
| 10 import 'package:sky/widgets/floating_action_button.dart'; | 10 import 'package:sky/widgets/floating_action_button.dart'; |
| 11 import 'package:sky/widgets/icon.dart'; | 11 import 'package:sky/widgets/icon.dart'; |
| 12 import 'package:sky/widgets/icon_button.dart'; | 12 import 'package:sky/widgets/icon_button.dart'; |
| 13 import 'package:sky/widgets/menu_divider.dart'; | 13 import 'package:sky/widgets/menu_divider.dart'; |
| 14 import 'package:sky/widgets/menu_item.dart'; | 14 import 'package:sky/widgets/menu_item.dart'; |
| 15 import 'package:sky/widgets/modal_overlay.dart'; | 15 import 'package:sky/widgets/modal_overlay.dart'; |
| 16 import 'package:sky/widgets/navigator.dart'; | 16 import 'package:sky/widgets/navigator.dart'; |
| 17 import 'package:sky/widgets/popup_menu.dart'; | 17 import 'package:sky/widgets/popup_menu.dart'; |
| 18 import 'package:sky/widgets/radio.dart'; | 18 import 'package:sky/widgets/radio.dart'; |
| 19 import 'package:sky/widgets/scaffold.dart'; | 19 import 'package:sky/widgets/scaffold.dart'; |
| 20 import 'package:sky/widgets/tool_bar.dart'; | 20 import 'package:sky/widgets/tool_bar.dart'; |
| 21 import 'package:sky/widgets/widget.dart'; | 21 import 'package:sky/widgets/widget.dart'; |
| 22 | 22 |
| 23 import 'stock_data.dart'; | 23 import 'stock_data.dart'; |
| 24 import 'stock_list.dart'; | 24 import 'stock_list.dart'; |
| 25 import 'stock_menu.dart'; | 25 import 'stock_menu.dart'; |
| 26 import 'stock_types.dart'; |
| 26 | 27 |
| 27 enum StockMode { optimistic, pessimistic } | 28 typedef void ModeUpdater(StockMode mode); |
| 28 | 29 |
| 29 class StockHome extends Component { | 30 class StockHome extends Component { |
| 30 | 31 |
| 31 StockHome(this.navigator, RouteBase route, this.stocks) : super(stateful: true
) { | 32 StockHome(this.navigator, this.stocks, this.stockMode, this.modeUpdater) : sup
er(stateful: true) { |
| 32 // if (debug) | 33 // if (debug) |
| 33 // new Timer(new Duration(seconds: 1), dumpState); | 34 // new Timer(new Duration(seconds: 1), dumpState); |
| 34 _drawerController = new DrawerController(_handleDrawerStatusChanged); | 35 _drawerController = new DrawerController(_handleDrawerStatusChanged); |
| 35 } | 36 } |
| 36 | 37 |
| 38 Navigator navigator; |
| 39 List<Stock> stocks; |
| 40 StockMode stockMode; |
| 41 ModeUpdater modeUpdater; |
| 42 |
| 37 void syncFields(StockHome source) { | 43 void syncFields(StockHome source) { |
| 38 navigator = source.navigator; | 44 navigator = source.navigator; |
| 39 stocks = source.stocks; | 45 stocks = source.stocks; |
| 46 stockMode = source.stockMode; |
| 47 modeUpdater = source.modeUpdater; |
| 40 } | 48 } |
| 41 | 49 |
| 42 Navigator navigator; | |
| 43 List<Stock> stocks; | |
| 44 | |
| 45 bool _isSearching = false; | 50 bool _isSearching = false; |
| 46 String _searchQuery; | 51 String _searchQuery; |
| 47 | 52 |
| 48 void _handleSearchBegin() { | 53 void _handleSearchBegin() { |
| 49 setState(() { | 54 setState(() { |
| 50 _isSearching = true; | 55 _isSearching = true; |
| 51 }); | 56 }); |
| 52 } | 57 } |
| 53 | 58 |
| 54 void _handleSearchEnd() { | 59 void _handleSearchEnd() { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 }); | 100 }); |
| 96 } | 101 } |
| 97 | 102 |
| 98 bool _autorefresh = false; | 103 bool _autorefresh = false; |
| 99 void _handleAutorefreshChanged(bool value) { | 104 void _handleAutorefreshChanged(bool value) { |
| 100 setState(() { | 105 setState(() { |
| 101 _autorefresh = value; | 106 _autorefresh = value; |
| 102 }); | 107 }); |
| 103 } | 108 } |
| 104 | 109 |
| 105 StockMode _stockMode = StockMode.optimistic; | |
| 106 void _handleStockModeChange(StockMode value) { | 110 void _handleStockModeChange(StockMode value) { |
| 107 setState(() { | 111 setState(() { |
| 108 _stockMode = value; | 112 stockMode = value; |
| 109 }); | 113 }); |
| 114 if (modeUpdater != null) |
| 115 modeUpdater(value); |
| 110 } | 116 } |
| 111 | 117 |
| 112 Drawer buildDrawer() { | 118 Drawer buildDrawer() { |
| 113 return new Drawer( | 119 return new Drawer( |
| 114 controller: _drawerController, | 120 controller: _drawerController, |
| 115 level: 3, | 121 level: 3, |
| 116 children: [ | 122 children: [ |
| 117 new DrawerHeader(children: [new Text('Stocks')]), | 123 new DrawerHeader(children: [new Text('Stocks')]), |
| 118 new MenuItem( | 124 new MenuItem( |
| 119 icon: 'action/assessment', | 125 icon: 'action/assessment', |
| 120 children: [new Text('Stock List')]), | 126 children: [new Text('Stock List')]), |
| 121 new MenuItem( | 127 new MenuItem( |
| 122 icon: 'action/account_balance', | 128 icon: 'action/account_balance', |
| 123 children: [new Text('Account Balance')]), | 129 children: [new Text('Account Balance')]), |
| 124 new MenuDivider(), | 130 new MenuDivider(), |
| 125 new MenuItem( | 131 new MenuItem( |
| 126 icon: 'action/thumb_up', | 132 icon: 'action/thumb_up', |
| 127 onPressed: () => _handleStockModeChange(StockMode.optimistic), | 133 onPressed: () => _handleStockModeChange(StockMode.optimistic), |
| 128 children: [ | 134 children: [ |
| 129 new Flexible(child: new Text('Optimistic')), | 135 new Flexible(child: new Text('Optimistic')), |
| 130 new Radio(value: StockMode.optimistic, groupValue: _stockMode, onCha
nged: _handleStockModeChange) | 136 new Radio(value: StockMode.optimistic, groupValue: stockMode, onChan
ged: _handleStockModeChange) |
| 131 ]), | 137 ]), |
| 132 new MenuItem( | 138 new MenuItem( |
| 133 icon: 'action/thumb_down', | 139 icon: 'action/thumb_down', |
| 134 onPressed: () => _handleStockModeChange(StockMode.pessimistic), | 140 onPressed: () => _handleStockModeChange(StockMode.pessimistic), |
| 135 children: [ | 141 children: [ |
| 136 new Flexible(child: new Text('Pessimistic')), | 142 new Flexible(child: new Text('Pessimistic')), |
| 137 new Radio(value: StockMode.pessimistic, groupValue: _stockMode, onCh
anged: _handleStockModeChange) | 143 new Radio(value: StockMode.pessimistic, groupValue: stockMode, onCha
nged: _handleStockModeChange) |
| 138 ]), | 144 ]), |
| 139 new MenuDivider(), | 145 new MenuDivider(), |
| 140 new MenuItem( | 146 new MenuItem( |
| 141 icon: 'action/settings', | 147 icon: 'action/settings', |
| 142 onPressed: () => navigator.pushNamed('/settings'), | 148 onPressed: () => navigator.pushNamed('/settings'), |
| 143 children: [new Text('Settings')]), | 149 children: [new Text('Settings')]), |
| 144 new MenuItem( | 150 new MenuItem( |
| 145 icon: 'action/help', | 151 icon: 'action/help', |
| 146 children: [new Text('Help & Feedback')]) | 152 children: [new Text('Help & Feedback')]) |
| 147 ] | 153 ] |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 floatingActionButton: new FloatingActionButton( | 212 floatingActionButton: new FloatingActionButton( |
| 207 child: new Icon(type: 'content/add_white', size: 24) | 213 child: new Icon(type: 'content/add_white', size: 24) |
| 208 ), | 214 ), |
| 209 drawer: _drawerShowing ? buildDrawer() : null | 215 drawer: _drawerShowing ? buildDrawer() : null |
| 210 ), | 216 ), |
| 211 ]; | 217 ]; |
| 212 addMenuToOverlays(overlays); | 218 addMenuToOverlays(overlays); |
| 213 return new Stack(overlays); | 219 return new Stack(overlays); |
| 214 } | 220 } |
| 215 } | 221 } |
| OLD | NEW |