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 'basic.dart'; | 5 import 'basic.dart'; |
6 import 'button_base.dart'; | 6 import 'button_base.dart'; |
7 import 'icon.dart'; | 7 import 'icon.dart'; |
8 import 'ink_well.dart'; | 8 import 'ink_well.dart'; |
9 import 'widget.dart'; | 9 import 'widget.dart'; |
10 | 10 |
11 const BoxDecoration _kHighlightDecoration = const BoxDecoration( | 11 const BoxDecoration _kHighlightDecoration = const BoxDecoration( |
12 backgroundColor: const Color.fromARGB(102, 153, 153, 153) | 12 backgroundColor: const Color.fromARGB(102, 153, 153, 153) |
13 ); | 13 ); |
14 | 14 |
15 // TODO(abarth): We shouldn't need _kHighlightBoring, but currently Container | 15 // TODO(abarth): We shouldn't need _kHighlightBoring, but currently Container |
16 // isn't smart enough to retain the components it builds when we | 16 // isn't smart enough to retain the components it builds when we |
17 // add or remove a |decoration|. For now, we use a transparent | 17 // add or remove a |decoration|. For now, we use a transparent |
18 // decoration to avoid changing the structure of the tree. The | 18 // decoration to avoid changing the structure of the tree. The |
19 // right fix, however, is to make Container smarter about how it | 19 // right fix, however, is to make Container smarter about how it |
20 // syncs its subcomponents. | 20 // syncs its subcomponents. |
21 const BoxDecoration _kHighlightBoring = const BoxDecoration( | 21 const BoxDecoration _kHighlightBoring = const BoxDecoration( |
22 backgroundColor: const Color.fromARGB(0, 0, 0, 0) | 22 backgroundColor: const Color.fromARGB(0, 0, 0, 0) |
23 ); | 23 ); |
24 | 24 |
25 class MenuItem extends ButtonBase { | 25 class MenuItem extends ButtonBase { |
26 MenuItem({ String key, this.icon, this.children, this.onGestureTap }) | 26 MenuItem({ String key, this.icon, this.children, this.onPressed }) |
27 : super(key: key); | 27 : super(key: key); |
28 | 28 |
29 String icon; | 29 String icon; |
30 List<Widget> children; | 30 List<Widget> children; |
31 GestureEventListener onGestureTap; | 31 Function onPressed; |
32 | 32 |
33 void syncFields(MenuItem source) { | 33 void syncFields(MenuItem source) { |
34 icon = source.icon; | 34 icon = source.icon; |
35 children = source.children; | 35 children = source.children; |
36 onGestureTap = source.onGestureTap; | 36 onPressed = source.onPressed; |
37 super.syncFields(source); | 37 super.syncFields(source); |
38 } | 38 } |
39 | 39 |
40 Widget buildContent() { | 40 Widget buildContent() { |
41 return new Listener( | 41 return new Listener( |
| 42 onGestureTap: (_) { |
| 43 if (onPressed != null) |
| 44 onPressed(); |
| 45 }, |
42 child: new Container( | 46 child: new Container( |
| 47 height: 48.0, |
| 48 decoration: highlight ? _kHighlightDecoration : _kHighlightBoring, |
43 child: new InkWell( | 49 child: new InkWell( |
44 child: new Flex([ | 50 child: new Flex([ |
45 new Padding( | 51 new Padding( |
46 child: new Icon(type: "${icon}_grey600", size: 24), | 52 padding: const EdgeDims.symmetric(horizontal: 16.0), |
47 padding: const EdgeDims.symmetric(horizontal: 16.0) | 53 child: new Icon(type: "${icon}_grey600", size: 24) |
48 ), | 54 ), |
49 new Flexible( | 55 new Flexible( |
| 56 flex: 1, |
50 child: new Padding( | 57 child: new Padding( |
| 58 padding: const EdgeDims.symmetric(horizontal: 16.0) |
51 child: new Flex(children, direction: FlexDirection.horizontal), | 59 child: new Flex(children, direction: FlexDirection.horizontal), |
52 padding: const EdgeDims.symmetric(horizontal: 16.0) | 60 ) |
53 ), | |
54 flex: 1 | |
55 ) | 61 ) |
56 ]) | 62 ]) |
57 ), | 63 ) |
58 height: 48.0, | 64 ) |
59 decoration: highlight ? _kHighlightDecoration : _kHighlightBoring | |
60 ), | |
61 onGestureTap: onGestureTap | |
62 ); | 65 ); |
63 } | 66 } |
64 } | 67 } |
OLD | NEW |