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 '../theme2/colors.dart'; | 5 import '../theme2/colors.dart'; |
6 import '../theme2/edges.dart'; | 6 import '../theme2/edges.dart'; |
7 import 'basic.dart'; | 7 import 'basic.dart'; |
8 import 'button_base.dart'; | 8 import 'button_base.dart'; |
9 import 'ink_well.dart'; | 9 import 'ink_well.dart'; |
10 import 'material.dart'; | 10 import 'material.dart'; |
11 | 11 |
12 enum RaisedButtonTheme { light, dark } | 12 enum RaisedButtonTheme { light, dark } |
13 | 13 |
14 class RaisedButton extends ButtonBase { | 14 class RaisedButton extends ButtonBase { |
15 | 15 |
16 RaisedButton({ Object key, this.child, this.onPressed, this.theme: RaisedButto nTheme.light }) : super(key: key); | 16 RaisedButton({ |
17 Object key, | |
18 this.child, | |
19 this.enabled: true, | |
20 this.onPressed, | |
21 this.theme: RaisedButtonTheme.light | |
22 }) : super(key: key); | |
17 | 23 |
18 UINode child; | 24 UINode child; |
19 int level; | 25 bool enabled; |
20 Function onPressed; | 26 Function onPressed; |
21 RaisedButtonTheme theme; | 27 RaisedButtonTheme theme; |
22 | 28 |
23 void syncFields(RaisedButton source) { | 29 void syncFields(RaisedButton source) { |
24 child = source.child; | 30 child = source.child; |
25 level = source.level; | 31 enabled = source.enabled; |
26 onPressed = source.onPressed; | 32 onPressed = source.onPressed; |
33 theme = source.theme; | |
27 super.syncFields(source); | 34 super.syncFields(source); |
28 } | 35 } |
29 | 36 |
30 UINode buildContent() { | 37 UINode buildContent() { |
38 UINode contents = new Container( | |
39 padding: new EdgeDims.symmetric(horizontal: 8.0), | |
40 child: new Center(child: child) // TODO(ianh): figure out a way to compell the child to have gray text when disabled... | |
41 ); | |
31 return new EventListenerNode( | 42 return new EventListenerNode( |
32 new Container( | 43 new Container( |
33 height: 36.0, | 44 height: 36.0, |
34 constraints: new BoxConstraints(minWidth: 88.0), | 45 constraints: new BoxConstraints(minWidth: 88.0), |
35 margin: new EdgeDims.all(4.0), | 46 margin: new EdgeDims.all(4.0), |
36 child: new Material( | 47 child: new Material( |
37 edge: MaterialEdge.card, | 48 edge: MaterialEdge.card, |
38 child: new InkWell( | 49 child: enabled ? new InkWell(child: contents) : contents, |
39 child: new Container( | 50 level: enabled ? (highlight ? 2 : 1) : 0, |
40 padding: new EdgeDims.symmetric(horizontal: 8.0), | |
41 child: new Center(child: child) | |
42 ) | |
43 ), | |
44 level: highlight ? 2 : 1, | |
45 color: theme == RaisedButtonTheme.light | 51 color: theme == RaisedButtonTheme.light |
jackson
2015/06/16 00:16:01
might want to work this out ahead of time for read
| |
46 ? (highlight ? Grey[350] : Grey[300]) | 52 ? (enabled ? (highlight ? Grey[350] : Grey[300]) : (Grey[350])) |
47 : (highlight ? Blue[700] : Blue[600]) | 53 : (enabled ? (highlight ? Blue[700] : Blue[600]) : (Grey[350])) |
48 ) | 54 ) |
49 ), | 55 ), |
50 onGestureTap: (_) { if (onPressed != null) onPressed(); } | 56 onGestureTap: (_) { if (onPressed != null && enabled) onPressed(); } |
51 ); | 57 ); |
52 } | 58 } |
53 | 59 |
54 } | 60 } |
OLD | NEW |