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 'ink_well.dart'; | 7 import 'ink_well.dart'; |
8 import 'material.dart'; | 8 import 'material.dart'; |
9 | 9 |
10 enum MaterialButtonTheme { light, dark } | |
11 | |
12 // Rather than using this class directly, please use FlatButton or RaisedButton. | 10 // Rather than using this class directly, please use FlatButton or RaisedButton. |
13 abstract class MaterialButton extends ButtonBase { | 11 abstract class MaterialButton extends ButtonBase { |
14 | 12 |
15 MaterialButton({ | 13 MaterialButton({ |
16 String key, | 14 String key, |
17 this.child, | 15 this.child, |
18 this.enabled: true, | 16 this.enabled: true, |
19 this.onPressed, | 17 this.onPressed |
20 this.theme: MaterialButtonTheme.light | |
21 }) : super(key: key); | 18 }) : super(key: key); |
22 | 19 |
23 Widget child; | 20 Widget child; |
24 bool enabled; | 21 bool enabled; |
25 Function onPressed; | 22 Function onPressed; |
26 MaterialButtonTheme theme; | |
27 | 23 |
28 void syncFields(MaterialButton source) { | 24 void syncFields(MaterialButton source) { |
29 child = source.child; | 25 child = source.child; |
30 enabled = source.enabled; | 26 enabled = source.enabled; |
31 onPressed = source.onPressed; | 27 onPressed = source.onPressed; |
32 theme = source.theme; | |
33 super.syncFields(source); | 28 super.syncFields(source); |
34 } | 29 } |
35 | 30 |
36 Color get color; | 31 Color get color; |
37 int get level; | 32 int get level; |
38 | 33 |
39 Widget buildContent() { | 34 Widget buildContent() { |
40 Widget contents = new Container( | 35 Widget contents = new Container( |
41 padding: new EdgeDims.symmetric(horizontal: 8.0), | 36 padding: new EdgeDims.symmetric(horizontal: 8.0), |
42 child: new Center(child: child) // TODO(ianh): figure out a way to compell
the child to have gray text when disabled... | 37 child: new Center(child: child) // TODO(ianh): figure out a way to compell
the child to have gray text when disabled... |
43 ); | 38 ); |
44 return new Listener( | 39 return new Listener( |
45 child: new Container( | 40 child: new Container( |
46 height: 36.0, | 41 height: 36.0, |
47 constraints: new BoxConstraints(minWidth: 88.0), | 42 constraints: new BoxConstraints(minWidth: 88.0), |
48 margin: new EdgeDims.all(8.0), | 43 margin: new EdgeDims.all(8.0), |
49 child: new Material( | 44 child: new Material( |
50 child: enabled ? new InkWell(child: contents) : contents, | 45 child: enabled ? new InkWell(child: contents) : contents, |
51 level: level, | 46 level: level, |
52 color: color | 47 color: color |
53 ) | 48 ) |
54 ), | 49 ), |
55 onGestureTap: (_) { if (onPressed != null && enabled) onPressed(); } | 50 onGestureTap: (_) { if (onPressed != null && enabled) onPressed(); } |
56 ); | 51 ); |
57 } | 52 } |
58 | 53 |
59 } | 54 } |
OLD | NEW |