| 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/framework/components/action_bar.dart'; | 5 import 'package:sky/framework/components/action_bar.dart'; |
| 6 import 'package:sky/framework/components/drawer.dart'; | 6 import 'package:sky/framework/components/drawer.dart'; |
| 7 import 'package:sky/framework/components/drawer_header.dart'; | 7 import 'package:sky/framework/components/drawer_header.dart'; |
| 8 import 'package:sky/framework/components/floating_action_button.dart'; | 8 import 'package:sky/framework/components/floating_action_button.dart'; |
| 9 import 'package:sky/framework/components/icon.dart'; | 9 import 'package:sky/framework/components/icon.dart'; |
| 10 import 'package:sky/framework/components/icon_button.dart'; | 10 import 'package:sky/framework/components/icon_button.dart'; |
| 11 import 'package:sky/framework/components/input.dart'; | 11 import 'package:sky/framework/components/input.dart'; |
| 12 import 'package:sky/framework/components/menu_divider.dart'; | 12 import 'package:sky/framework/components/menu_divider.dart'; |
| 13 import 'package:sky/framework/components/menu_item.dart'; | 13 import 'package:sky/framework/components/menu_item.dart'; |
| 14 import 'package:sky/framework/components/modal_overlay.dart'; | 14 import 'package:sky/framework/components/modal_overlay.dart'; |
| 15 import 'package:sky/framework/components/popup_menu.dart'; | 15 import 'package:sky/framework/components/popup_menu.dart'; |
| 16 import 'package:sky/framework/components/radio.dart'; |
| 16 import 'package:sky/framework/components/scaffold.dart'; | 17 import 'package:sky/framework/components/scaffold.dart'; |
| 17 import 'package:sky/framework/fn.dart'; | 18 import 'package:sky/framework/fn.dart'; |
| 18 import 'package:sky/framework/theme/typography.dart' as typography; | 19 import 'package:sky/framework/theme/typography.dart' as typography; |
| 19 import 'package:sky/framework/theme/colors.dart'; | 20 import 'package:sky/framework/theme/colors.dart'; |
| 20 import 'stock_data.dart'; | 21 import 'stock_data.dart'; |
| 21 import 'stock_list.dart'; | 22 import 'stock_list.dart'; |
| 22 import 'stock_menu.dart'; | 23 import 'stock_menu.dart'; |
| 23 | 24 |
| 24 import 'dart:async'; | 25 import 'dart:async'; |
| 25 import 'package:sky/framework/layout.dart'; | 26 import 'package:sky/framework/layout.dart'; |
| 26 | 27 |
| 27 const bool debug = false; // set to true to dump the DOM for debugging purposes | 28 const bool debug = false; // set to true to dump the DOM for debugging purposes |
| 28 | 29 |
| 30 enum StockMode { Optimistic, Pessimistic } |
| 31 |
| 29 class StocksApp extends App { | 32 class StocksApp extends App { |
| 30 | 33 |
| 31 static final Style _actionBarStyle = new Style(''' | 34 static final Style _actionBarStyle = new Style(''' |
| 32 background-color: ${Purple[500]};'''); | 35 background-color: ${Purple[500]};'''); |
| 33 | 36 |
| 34 static final Style _searchBarStyle = new Style(''' | 37 static final Style _searchBarStyle = new Style(''' |
| 35 background-color: ${Grey[50]};'''); | 38 background-color: ${Grey[50]};'''); |
| 36 | 39 |
| 37 static final Style _titleStyle = new Style(''' | 40 static final Style _titleStyle = new Style(''' |
| 38 ${typography.white.title};'''); | 41 ${typography.white.title};'''); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 void _handleMenuHide(_) { | 96 void _handleMenuHide(_) { |
| 94 setState(() { | 97 setState(() { |
| 95 _menuController.close().then((_) { | 98 _menuController.close().then((_) { |
| 96 setState(() { | 99 setState(() { |
| 97 _menuController = null; | 100 _menuController = null; |
| 98 }); | 101 }); |
| 99 }); | 102 }); |
| 100 }); | 103 }); |
| 101 } | 104 } |
| 102 | 105 |
| 106 bool _autorefresh = false; |
| 107 void _handleAutorefreshChanged(bool value) { |
| 108 setState(() { |
| 109 _autorefresh = value; |
| 110 }); |
| 111 } |
| 112 |
| 113 StockMode _stockMode = StockMode.Optimistic; |
| 114 void _handleStockModeChange(StockMode value) { |
| 115 setState(() { |
| 116 _stockMode = value; |
| 117 }); |
| 118 } |
| 119 |
| 120 static FlexBoxParentData _flex1 = new FlexBoxParentData()..flex = 1; |
| 121 |
| 103 Drawer buildDrawer() { | 122 Drawer buildDrawer() { |
| 104 return new Drawer( | 123 return new Drawer( |
| 105 controller: _drawerController, | 124 controller: _drawerController, |
| 106 level: 3, | 125 level: 3, |
| 107 children: [ | 126 children: [ |
| 108 new DrawerHeader(children: [new Text('Stocks')]), | 127 new DrawerHeader(children: [new Text('Stocks')]), |
| 109 new MenuItem( | 128 new MenuItem( |
| 110 key: 'Inbox', | 129 key: 'Stock list', |
| 111 icon: 'content/inbox', | 130 icon: 'action/assessment', |
| 112 children: [new Text('Inbox')]), | 131 children: [new Text('Stock List')]), |
| 113 new MenuDivider(), | |
| 114 new MenuItem( | 132 new MenuItem( |
| 115 key: 'Drafts', | 133 key: 'Account Balance', |
| 116 icon: 'content/drafts', | 134 icon: 'action/account_balance', |
| 117 children: [new Text('Drafts')]), | 135 children: [new Text('Account Balance')]), |
| 136 new MenuDivider(key: 'div1'), |
| 137 new MenuItem( |
| 138 key: 'Optimistic Menu Item', |
| 139 icon: 'action/thumb_up', |
| 140 onGestureTap: (event) => _handleStockModeChange(StockMode.Optimistic), |
| 141 children: [ |
| 142 new ParentDataNode(new Text('Optimistic'), _flex1), |
| 143 new Radio(key: 'optimistic-radio', value: StockMode.Optimistic, grou
pValue: _stockMode, onChanged: _handleStockModeChange) |
| 144 ]), |
| 145 new MenuItem( |
| 146 key: 'Pessimistic Menu Item', |
| 147 icon: 'action/thumb_down', |
| 148 onGestureTap: (event) => _handleStockModeChange(StockMode.Pessimistic)
, |
| 149 children: [ |
| 150 new ParentDataNode(new Text('Pessimistic'), _flex1), |
| 151 new Radio(key: 'pessimistic-radio', value: StockMode.Pessimistic, gr
oupValue: _stockMode, onChanged: _handleStockModeChange) |
| 152 ]), |
| 153 new MenuDivider(key: 'div2'), |
| 118 new MenuItem( | 154 new MenuItem( |
| 119 key: 'Settings', | 155 key: 'Settings', |
| 120 icon: 'action/settings', | 156 icon: 'action/settings', |
| 121 children: [new Text('Settings')]), | 157 children: [new Text('Settings')]), |
| 122 new MenuItem( | 158 new MenuItem( |
| 123 key: 'Help & Feedback', | 159 key: 'Help & Feedback', |
| 124 icon: 'action/help', | 160 icon: 'action/help', |
| 125 children: [new Text('Help & Feedback')]) | 161 children: [new Text('Help & Feedback')]) |
| 126 ] | 162 ] |
| 127 ); | 163 ); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 158 focused: true, | 194 focused: true, |
| 159 placeholder: 'Search stocks', | 195 placeholder: 'Search stocks', |
| 160 onChanged: _handleSearchQueryChanged)), | 196 onChanged: _handleSearchQueryChanged)), |
| 161 _searchBarStyle); | 197 _searchBarStyle); |
| 162 } | 198 } |
| 163 | 199 |
| 164 void addMenuToOverlays(List<UINode> overlays) { | 200 void addMenuToOverlays(List<UINode> overlays) { |
| 165 if (_menuController == null) | 201 if (_menuController == null) |
| 166 return; | 202 return; |
| 167 overlays.add(new ModalOverlay( | 203 overlays.add(new ModalOverlay( |
| 168 children: [new StockMenu(controller: _menuController)], | 204 children: [new StockMenu( |
| 205 controller: _menuController, |
| 206 autorefresh: _autorefresh, |
| 207 onAutorefreshChanged: _handleAutorefreshChanged |
| 208 )], |
| 169 onDismiss: _handleMenuHide)); | 209 onDismiss: _handleMenuHide)); |
| 170 } | 210 } |
| 171 | 211 |
| 172 UINode build() { | 212 UINode build() { |
| 173 List<UINode> overlays = []; | 213 List<UINode> overlays = []; |
| 174 addMenuToOverlays(overlays); | 214 addMenuToOverlays(overlays); |
| 175 | 215 |
| 176 return new Scaffold( | 216 return new Scaffold( |
| 177 header: _isSearching ? buildSearchBar() : buildActionBar(), | 217 header: _isSearching ? buildSearchBar() : buildActionBar(), |
| 178 content: new Stocklist(stocks: _stocks, query: _searchQuery), | 218 content: new Stocklist(stocks: _stocks, query: _searchQuery), |
| 179 fab: new FloatingActionButton( | 219 fab: new FloatingActionButton( |
| 180 content: new Icon(type: 'content/add_white', size: 24), level: 3), | 220 content: new Icon(type: 'content/add_white', size: 24), level: 3), |
| 181 drawer: _drawerShowing ? buildDrawer() : null, | 221 drawer: _drawerShowing ? buildDrawer() : null, |
| 182 overlays: overlays | 222 overlays: overlays |
| 183 ); | 223 ); |
| 184 } | 224 } |
| 185 } | 225 } |
| OLD | NEW |