| 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/animation/animation_performance.dart'; | 6 import 'package:sky/animation/animation_performance.dart'; |
| 7 import 'package:sky/widgets/animated_component.dart'; | 7 import 'package:sky/widgets/animated_component.dart'; |
| 8 import 'package:sky/widgets/animation_builder.dart'; | 8 import 'package:sky/widgets/animation_builder.dart'; |
| 9 import 'package:sky/theme/colors.dart' as colors; | 9 import 'package:sky/theme/colors.dart' as colors; |
| 10 import 'package:sky/widgets/basic.dart'; | 10 import 'package:sky/widgets/basic.dart'; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 import 'stock_list.dart'; | 30 import 'stock_list.dart'; |
| 31 import 'stock_menu.dart'; | 31 import 'stock_menu.dart'; |
| 32 import 'stock_types.dart'; | 32 import 'stock_types.dart'; |
| 33 | 33 |
| 34 typedef void ModeUpdater(StockMode mode); | 34 typedef void ModeUpdater(StockMode mode); |
| 35 | 35 |
| 36 const Duration _kSnackbarSlideDuration = const Duration(milliseconds: 200); | 36 const Duration _kSnackbarSlideDuration = const Duration(milliseconds: 200); |
| 37 | 37 |
| 38 class StockHome extends AnimatedComponent { | 38 class StockHome extends AnimatedComponent { |
| 39 | 39 |
| 40 StockHome(this.navigator, this.stocks, this.stockMode, this.modeUpdater) { | 40 StockHome(this.navigator, this.stocks, this.stockMode, this.modeUpdater); |
| 41 // if (debug) | |
| 42 // new Timer(new Duration(seconds: 1), dumpState); | |
| 43 _drawerController = new DrawerController(_handleDrawerStatusChanged); | |
| 44 } | |
| 45 | 41 |
| 46 Navigator navigator; | 42 Navigator navigator; |
| 47 List<Stock> stocks; | 43 List<Stock> stocks; |
| 48 StockMode stockMode; | 44 StockMode stockMode; |
| 49 ModeUpdater modeUpdater; | 45 ModeUpdater modeUpdater; |
| 50 | 46 |
| 51 void syncFields(StockHome source) { | 47 void syncFields(StockHome source) { |
| 52 navigator = source.navigator; | 48 navigator = source.navigator; |
| 53 stocks = source.stocks; | 49 stocks = source.stocks; |
| 54 stockMode = source.stockMode; | 50 stockMode = source.stockMode; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 81 _searchQuery = null; | 77 _searchQuery = null; |
| 82 }); | 78 }); |
| 83 } | 79 } |
| 84 | 80 |
| 85 void _handleSearchQueryChanged(String query) { | 81 void _handleSearchQueryChanged(String query) { |
| 86 setState(() { | 82 setState(() { |
| 87 _searchQuery = query; | 83 _searchQuery = query; |
| 88 }); | 84 }); |
| 89 } | 85 } |
| 90 | 86 |
| 91 DrawerController _drawerController; | |
| 92 bool _drawerShowing = false; | 87 bool _drawerShowing = false; |
| 88 DrawerStatus _drawerStatus = DrawerStatus.inactive; |
| 93 | 89 |
| 94 void _handleDrawerStatusChanged(bool showing) { | 90 void _handleOpenDrawer() { |
| 95 if (!showing && navigator.currentRoute.name == "/drawer") { | 91 setState(() { |
| 92 _drawerShowing = true; |
| 93 _drawerStatus = DrawerStatus.active; |
| 94 }); |
| 95 } |
| 96 |
| 97 void _handleDrawerStatusChange(DrawerStatus status) { |
| 98 if (status == DrawerStatus.inactive && navigator.currentRoute.name == "/draw
er") { |
| 96 navigator.pop(); | 99 navigator.pop(); |
| 97 } | 100 } |
| 98 setState(() { | 101 setState(() { |
| 99 _drawerShowing = showing; | 102 _drawerStatus = status; |
| 100 }); | 103 }); |
| 101 } | 104 } |
| 102 | 105 |
| 103 bool _menuShowing = false; | 106 bool _menuShowing = false; |
| 104 PopupMenuStatus _menuStatus = PopupMenuStatus.inactive; | 107 PopupMenuStatus _menuStatus = PopupMenuStatus.inactive; |
| 105 | 108 |
| 106 void _handleMenuShow() { | 109 void _handleMenuShow() { |
| 107 setState(() { | 110 setState(() { |
| 108 _menuShowing = true; | 111 _menuShowing = true; |
| 109 _menuStatus = PopupMenuStatus.active; | 112 _menuStatus = PopupMenuStatus.active; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 131 | 134 |
| 132 void _handleStockModeChange(StockMode value) { | 135 void _handleStockModeChange(StockMode value) { |
| 133 setState(() { | 136 setState(() { |
| 134 stockMode = value; | 137 stockMode = value; |
| 135 }); | 138 }); |
| 136 if (modeUpdater != null) | 139 if (modeUpdater != null) |
| 137 modeUpdater(value); | 140 modeUpdater(value); |
| 138 } | 141 } |
| 139 | 142 |
| 140 Drawer buildDrawer() { | 143 Drawer buildDrawer() { |
| 144 if (_drawerStatus == DrawerStatus.inactive) |
| 145 return null; |
| 141 return new Drawer( | 146 return new Drawer( |
| 142 controller: _drawerController, | |
| 143 level: 3, | 147 level: 3, |
| 148 showing: _drawerShowing, |
| 149 onStatusChanged: _handleDrawerStatusChange, |
| 150 navigator: navigator, |
| 144 children: [ | 151 children: [ |
| 145 new DrawerHeader(children: [new Text('Stocks')]), | 152 new DrawerHeader(children: [new Text('Stocks')]), |
| 146 new DrawerItem( | 153 new DrawerItem( |
| 147 icon: 'action/assessment', | 154 icon: 'action/assessment', |
| 148 selected: true, | 155 selected: true, |
| 149 children: [new Text('Stock List')]), | 156 children: [new Text('Stock List')]), |
| 150 new DrawerItem( | 157 new DrawerItem( |
| 151 icon: 'action/account_balance', | 158 icon: 'action/account_balance', |
| 152 children: [new Text('Account Balance')]), | 159 children: [new Text('Account Balance')]), |
| 153 new DrawerDivider(), | 160 new DrawerDivider(), |
| (...skipping 17 matching lines...) Expand all Loading... |
| 171 onPressed: _handleShowSettings, | 178 onPressed: _handleShowSettings, |
| 172 children: [new Text('Settings')]), | 179 children: [new Text('Settings')]), |
| 173 new DrawerItem( | 180 new DrawerItem( |
| 174 icon: 'action/help', | 181 icon: 'action/help', |
| 175 children: [new Text('Help & Feedback')]) | 182 children: [new Text('Help & Feedback')]) |
| 176 ] | 183 ] |
| 177 ); | 184 ); |
| 178 } | 185 } |
| 179 | 186 |
| 180 void _handleShowSettings() { | 187 void _handleShowSettings() { |
| 181 assert(navigator.currentRoute.name == '/drawer'); | |
| 182 navigator.pop(); | 188 navigator.pop(); |
| 183 assert(navigator.currentRoute.name == '/'); | |
| 184 navigator.pushNamed('/settings'); | 189 navigator.pushNamed('/settings'); |
| 185 } | 190 } |
| 186 | 191 |
| 187 void _handleOpenDrawer() { | |
| 188 _drawerController.open(); | |
| 189 navigator.pushState("/drawer", (_) { | |
| 190 _drawerController.close(); | |
| 191 }); | |
| 192 } | |
| 193 | |
| 194 Widget buildToolBar() { | 192 Widget buildToolBar() { |
| 195 return new ToolBar( | 193 return new ToolBar( |
| 196 left: new IconButton( | 194 left: new IconButton( |
| 197 icon: "navigation/menu", | 195 icon: "navigation/menu", |
| 198 onPressed: _handleOpenDrawer), | 196 onPressed: _handleOpenDrawer), |
| 199 center: new Text('Stocks'), | 197 center: new Text('Stocks'), |
| 200 right: [ | 198 right: [ |
| 201 new IconButton( | 199 new IconButton( |
| 202 icon: "action/search", | 200 icon: "action/search", |
| 203 onPressed: _handleSearchBegin), | 201 onPressed: _handleSearchBegin), |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 onDismiss: _handleMenuHide)); | 316 onDismiss: _handleMenuHide)); |
| 319 } | 317 } |
| 320 | 318 |
| 321 Widget build() { | 319 Widget build() { |
| 322 List<Widget> overlays = [ | 320 List<Widget> overlays = [ |
| 323 new Scaffold( | 321 new Scaffold( |
| 324 toolbar: _isSearching ? buildSearchBar() : buildToolBar(), | 322 toolbar: _isSearching ? buildSearchBar() : buildToolBar(), |
| 325 body: buildTabNavigator(), | 323 body: buildTabNavigator(), |
| 326 snackBar: buildSnackBar(), | 324 snackBar: buildSnackBar(), |
| 327 floatingActionButton: buildFloatingActionButton(), | 325 floatingActionButton: buildFloatingActionButton(), |
| 328 drawer: _drawerShowing ? buildDrawer() : null | 326 drawer: buildDrawer() |
| 329 ), | 327 ), |
| 330 ]; | 328 ]; |
| 331 addMenuToOverlays(overlays); | 329 addMenuToOverlays(overlays); |
| 332 return new Stack(overlays); | 330 return new Stack(overlays); |
| 333 } | 331 } |
| 334 } | 332 } |
| OLD | NEW |