| 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 '../painting/text_style.dart'; | 5 import '../painting/text_style.dart'; |
| 6 import 'basic.dart'; | 6 import 'basic.dart'; |
| 7 import 'button_base.dart'; | 7 import 'button_base.dart'; |
| 8 import 'default_text_style.dart'; | 8 import 'default_text_style.dart'; |
| 9 import 'icon.dart'; | 9 import 'icon.dart'; |
| 10 import 'ink_well.dart'; | 10 import 'ink_well.dart'; |
| 11 import 'theme.dart'; | 11 import 'theme.dart'; |
| 12 import 'widget.dart'; | 12 import 'widget.dart'; |
| 13 | 13 |
| 14 const BoxDecoration _kHighlightDecoration = const BoxDecoration( | 14 const BoxDecoration _kHighlightDecoration = const BoxDecoration( |
| 15 backgroundColor: const Color.fromARGB(102, 153, 153, 153) | 15 backgroundColor: const Color.fromARGB(102, 153, 153, 153) |
| 16 ); | 16 ); |
| 17 | 17 |
| 18 // TODO(abarth): We shouldn't need _kHighlightBoring, but currently Container | 18 // TODO(abarth): We shouldn't need _kHighlightBoring, but currently Container |
| 19 // isn't smart enough to retain the components it builds when we | 19 // isn't smart enough to retain the components it builds when we |
| 20 // add or remove a |decoration|. For now, we use a transparent | 20 // add or remove a |decoration|. For now, we use a transparent |
| 21 // decoration to avoid changing the structure of the tree. The | 21 // decoration to avoid changing the structure of the tree. The |
| 22 // right fix, however, is to make Container smarter about how it | 22 // right fix, however, is to make Container smarter about how it |
| 23 // syncs its subcomponents. | 23 // syncs its subcomponents. |
| 24 const BoxDecoration _kHighlightBoring = const BoxDecoration( | 24 const BoxDecoration _kHighlightBoring = const BoxDecoration( |
| 25 backgroundColor: const Color.fromARGB(0, 0, 0, 0) | 25 backgroundColor: const Color.fromARGB(0, 0, 0, 0) |
| 26 ); | 26 ); |
| 27 | 27 |
| 28 class MenuItem extends ButtonBase { | 28 class MenuItem extends ButtonBase { |
| 29 MenuItem({ String key, this.icon, this.children, this.onPressed }) | 29 MenuItem({ String key, this.icon, this.children, this.onPressed, this.selected
: false }) |
| 30 : super(key: key); | 30 : super(key: key); |
| 31 | 31 |
| 32 String icon; | 32 String icon; |
| 33 List<Widget> children; | 33 List<Widget> children; |
| 34 Function onPressed; | 34 Function onPressed; |
| 35 bool selected; |
| 35 | 36 |
| 36 void syncFields(MenuItem source) { | 37 void syncFields(MenuItem source) { |
| 37 icon = source.icon; | 38 icon = source.icon; |
| 38 children = source.children; | 39 children = source.children; |
| 39 onPressed = source.onPressed; | 40 onPressed = source.onPressed; |
| 41 selected = source.selected; |
| 40 super.syncFields(source); | 42 super.syncFields(source); |
| 41 } | 43 } |
| 42 | 44 |
| 43 TextStyle get textStyle { | 45 TextStyle get textStyle { |
| 44 TextStyle result = Theme.of(this).text.body2; | 46 TextStyle result = Theme.of(this).text.body2; |
| 45 if (highlight) | 47 if (highlight) |
| 46 result = result.copyWith(color: Theme.of(this).primaryColor); | 48 result = result.copyWith(color: Theme.of(this).primaryColor); |
| 47 return result; | 49 return result; |
| 48 } | 50 } |
| 49 | 51 |
| 50 String get iconSuffix { | 52 String get iconSuffix { |
| 51 switch(Theme.of(this).brightness) { | 53 switch(Theme.of(this).brightness) { |
| 52 case ThemeBrightness.dark: | 54 case ThemeBrightness.dark: |
| 53 return "white"; | 55 return "white"; |
| 54 case ThemeBrightness.light: | 56 case ThemeBrightness.light: |
| 55 return "black"; | 57 return "black"; |
| 56 } | 58 } |
| 57 } | 59 } |
| 58 | 60 |
| 59 Widget buildContent() { | 61 Widget buildContent() { |
| 60 List<Widget> flexChildren = new List<Widget>(); | 62 List<Widget> flexChildren = new List<Widget>(); |
| 61 if (icon != null) { | 63 if (icon != null) { |
| 62 flexChildren.add( | 64 flexChildren.add( |
| 63 new Opacity( | 65 new Opacity( |
| 64 opacity: highlight ? 1.0 : 0.45, | 66 opacity: selected ? 1.0 : 0.45, |
| 65 child: new Padding( | 67 child: new Padding( |
| 66 padding: const EdgeDims.symmetric(horizontal: 16.0), | 68 padding: const EdgeDims.symmetric(horizontal: 16.0), |
| 67 child: new Icon(type: "${icon}_${iconSuffix}", size: 24) | 69 child: new Icon(type: "${icon}_${iconSuffix}", size: 24) |
| 68 ) | 70 ) |
| 69 ) | 71 ) |
| 70 ); | 72 ); |
| 71 } | 73 } |
| 72 flexChildren.add( | 74 flexChildren.add( |
| 73 new Flexible( | 75 new Flexible( |
| 74 child: new Padding( | 76 child: new Padding( |
| 75 padding: const EdgeDims.symmetric(horizontal: 16.0), | 77 padding: const EdgeDims.symmetric(horizontal: 16.0), |
| 76 child: new DefaultTextStyle( | 78 child: new DefaultTextStyle( |
| 77 style: textStyle, | 79 style: textStyle, |
| 78 child: new Flex(children, direction: FlexDirection.horizontal) | 80 child: new Flex(children, direction: FlexDirection.horizontal) |
| 79 ) | 81 ) |
| 80 ) | 82 ) |
| 81 ) | 83 ) |
| 82 ); | 84 ); |
| 83 return new Listener( | 85 return new Listener( |
| 84 onGestureTap: (_) { | 86 onGestureTap: (_) { |
| 85 if (onPressed != null) | 87 if (onPressed != null) |
| 86 onPressed(); | 88 onPressed(); |
| 87 }, | 89 }, |
| 88 child: new Container( | 90 child: new Container( |
| 89 height: 48.0, | 91 height: 48.0, |
| 90 decoration: highlight ? _kHighlightDecoration : _kHighlightBoring, | 92 decoration: selected ? _kHighlightDecoration : _kHighlightBoring, |
| 91 child: new InkWell( | 93 child: new Container( |
| 92 child: new Flex(flexChildren) | 94 decoration: highlight ? _kHighlightDecoration : _kHighlightBoring, |
| 95 child: new InkWell( |
| 96 child: new Flex(flexChildren) |
| 97 ) |
| 93 ) | 98 ) |
| 94 ) | 99 ) |
| 95 ); | 100 ); |
| 96 } | 101 } |
| 97 } | 102 } |
| OLD | NEW |