| OLD | NEW |
| (Empty) |
| 1 library stocksapp; | |
| 2 | |
| 3 import '../data/stocks.dart'; | |
| 4 import 'dart:math'; | |
| 5 import 'package:sky/framework/animation/scroll_behavior.dart'; | |
| 6 import 'package:sky/framework/components/action_bar.dart'; | |
| 7 import 'package:sky/framework/components/drawer.dart'; | |
| 8 import 'package:sky/framework/components/drawer_header.dart'; | |
| 9 import 'package:sky/framework/components/fixed_height_scrollable.dart'; | |
| 10 import 'package:sky/framework/components/floating_action_button.dart'; | |
| 11 import 'package:sky/framework/components/icon.dart'; | |
| 12 import 'package:sky/framework/components/input.dart'; | |
| 13 import 'package:sky/framework/components/material.dart'; | |
| 14 import 'package:sky/framework/components/menu_divider.dart'; | |
| 15 import 'package:sky/framework/components/menu_item.dart'; | |
| 16 import 'package:sky/framework/fn.dart'; | |
| 17 import 'package:sky/framework/theme/typography.dart' as typography; | |
| 18 | |
| 19 part 'stockarrow.dart'; | |
| 20 part 'stocklist.dart'; | |
| 21 part 'stockrow.dart'; | |
| 22 | |
| 23 class StocksApp extends App { | |
| 24 | |
| 25 DrawerAnimation _drawerAnimation = new DrawerAnimation(); | |
| 26 | |
| 27 static Style _style = new Style(''' | |
| 28 display: flex; | |
| 29 flex-direction: column; | |
| 30 height: -webkit-fill-available; | |
| 31 ${typography.typeface}; | |
| 32 ${typography.black.body1};''' | |
| 33 ); | |
| 34 | |
| 35 static Style _iconStyle = new Style(''' | |
| 36 padding: 8px;''' | |
| 37 ); | |
| 38 | |
| 39 static Style _titleStyle = new Style(''' | |
| 40 padding-left: 24px; | |
| 41 flex: 1; | |
| 42 ${typography.white.title};''' | |
| 43 ); | |
| 44 | |
| 45 List<Stock> _sortedStocks; | |
| 46 bool _isSearching = false; | |
| 47 String _searchQuery; | |
| 48 | |
| 49 StocksApp() : super() { | |
| 50 _sortedStocks = oracle.stocks; | |
| 51 _sortedStocks.sort((a, b) => a.symbol.compareTo(b.symbol)); | |
| 52 } | |
| 53 | |
| 54 void _handleSearchClick(_) { | |
| 55 setState(() { | |
| 56 _isSearching = !_isSearching; | |
| 57 }); | |
| 58 } | |
| 59 | |
| 60 void _handleSearchQueryChanged(query) { | |
| 61 setState(() { | |
| 62 _searchQuery = query; | |
| 63 }); | |
| 64 } | |
| 65 | |
| 66 Node build() { | |
| 67 var drawer = new Drawer( | |
| 68 animation: _drawerAnimation, | |
| 69 level: 3, | |
| 70 children: [ | |
| 71 new DrawerHeader( | |
| 72 children: [new Text('Stocks')] | |
| 73 ), | |
| 74 new MenuItem( | |
| 75 key: 'Inbox', | |
| 76 icon: 'content/inbox', | |
| 77 children: [new Text('Inbox')] | |
| 78 ), | |
| 79 new MenuDivider( | |
| 80 ), | |
| 81 new MenuItem( | |
| 82 key: 'Drafts', | |
| 83 icon: 'content/drafts', | |
| 84 children: [new Text('Drafts')] | |
| 85 ), | |
| 86 new MenuItem( | |
| 87 key: 'Settings', | |
| 88 icon: 'action/settings', | |
| 89 children: [new Text('Settings')] | |
| 90 ), | |
| 91 new MenuItem( | |
| 92 key: 'Help & Feedback', | |
| 93 icon: 'action/help', | |
| 94 children: [new Text('Help & Feedback')] | |
| 95 ) | |
| 96 ] | |
| 97 ); | |
| 98 | |
| 99 Node title; | |
| 100 if (_isSearching) { | |
| 101 title = new Input(focused: true, placeholder: 'Search stocks', | |
| 102 onChanged: _handleSearchQueryChanged); | |
| 103 } else { | |
| 104 title = new Text('Stocks'); | |
| 105 } | |
| 106 | |
| 107 var toolbar = new ActionBar( | |
| 108 children: [ | |
| 109 new Icon(key: 'menu', style: _iconStyle, | |
| 110 size: 24, | |
| 111 type: 'navigation/menu_white') | |
| 112 ..events.listen('gesturetap', _drawerAnimation.toggle), | |
| 113 new Container( | |
| 114 style: _titleStyle, | |
| 115 children: [title] | |
| 116 ), | |
| 117 new Icon(key: 'search', style: _iconStyle, | |
| 118 size: 24, | |
| 119 type: 'action/search_white') | |
| 120 ..events.listen('gesturetap', _handleSearchClick), | |
| 121 new Icon(key: 'more_white', style: _iconStyle, | |
| 122 size: 24, | |
| 123 type: 'navigation/more_vert_white') | |
| 124 ] | |
| 125 ); | |
| 126 | |
| 127 var list = new Stocklist(stocks: _sortedStocks, query: _searchQuery); | |
| 128 | |
| 129 var fab = new FloatingActionButton(content: new Icon( | |
| 130 type: 'content/add_white', size: 24), level: 3); | |
| 131 | |
| 132 return new Container( | |
| 133 key: 'StocksApp', | |
| 134 children: [ | |
| 135 new Container( | |
| 136 key: 'Content', | |
| 137 style: _style, | |
| 138 children: [toolbar, list] | |
| 139 ), | |
| 140 fab, | |
| 141 drawer, | |
| 142 ] | |
| 143 ); | |
| 144 } | |
| 145 } | |
| OLD | NEW |