| 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 '../animation/animation_performance.dart'; | 5 import '../animation/animation_performance.dart'; |
| 6 import '../painting/box_painter.dart'; | 6 import '../painting/box_painter.dart'; |
| 7 import 'animated_component.dart'; | 7 import 'animated_component.dart'; |
| 8 import 'animated_container.dart'; | 8 import 'animated_container.dart'; |
| 9 import 'basic.dart'; | 9 import 'basic.dart'; |
| 10 import 'default_text_style.dart'; | 10 import 'default_text_style.dart'; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 Material({ | 27 Material({ |
| 28 String key, | 28 String key, |
| 29 this.child, | 29 this.child, |
| 30 MaterialType type: MaterialType.card, | 30 MaterialType type: MaterialType.card, |
| 31 int level: 0, | 31 int level: 0, |
| 32 Color color: null | 32 Color color: null |
| 33 }) : super(key: key) { | 33 }) : super(key: key) { |
| 34 if (level == null) level = 0; | 34 if (level == null) level = 0; |
| 35 _container = new AnimatedContainer() | 35 _container = new AnimatedContainer() |
| 36 ..shadow = new AnimatedType<double>(level.toDouble()) | 36 ..shadow = new AnimatedType<double>(level.toDouble()) |
| 37 ..backgroundColor = new AnimatedColor(_getBackgroundColor(type, color)) | 37 ..backgroundColor = _getBackgroundColor(type, color) |
| 38 ..borderRadius = edges[type] | 38 ..borderRadius = edges[type] |
| 39 ..shape = type == MaterialType.circle ? Shape.circle : Shape.rectangle; | 39 ..shape = type == MaterialType.circle ? Shape.circle : Shape.rectangle; |
| 40 watchPerformance(_container.createPerformance( | 40 watchPerformance(_container.createPerformance( |
| 41 _container.shadow, duration: _kAnimateShadowDuration)); | 41 _container.shadow, duration: _kAnimateShadowDuration)); |
| 42 watchPerformance(_container.createPerformance( | 42 watchPerformance(_container.createPerformance( |
| 43 _container.backgroundColor, duration: _kAnimateColorDuration)); | 43 _container.backgroundColor, duration: _kAnimateColorDuration)); |
| 44 } | 44 } |
| 45 | 45 |
| 46 Widget child; | 46 Widget child; |
| 47 | 47 |
| 48 AnimatedContainer _container; | 48 AnimatedContainer _container; |
| 49 | 49 |
| 50 void syncFields(Material source) { | 50 void syncFields(Material source) { |
| 51 child = source.child; | 51 child = source.child; |
| 52 _container.syncFields(source._container); | 52 _container.syncFields(source._container); |
| 53 super.syncFields(source); | 53 super.syncFields(source); |
| 54 } | 54 } |
| 55 | 55 |
| 56 Color _getBackgroundColor(MaterialType type, Color color) { | 56 AnimatedColor _getBackgroundColor(MaterialType type, Color color) { |
| 57 if (color != null) | 57 if (color == null) { |
| 58 return color; | 58 switch (type) { |
| 59 switch (type) { | 59 case MaterialType.canvas: color = Theme.of(this).canvasColor; break; |
| 60 case MaterialType.canvas: | 60 case MaterialType.card: color = Theme.of(this).cardColor; break; |
| 61 return Theme.of(this).canvasColor; | 61 } |
| 62 case MaterialType.card: | |
| 63 return Theme.of(this).cardColor; | |
| 64 default: | |
| 65 return null; | |
| 66 } | 62 } |
| 63 return color == null ? null : new AnimatedColor(color); |
| 67 } | 64 } |
| 68 | 65 |
| 69 Widget build() { | 66 Widget build() { |
| 70 return _container.build( | 67 return _container.build( |
| 71 new DefaultTextStyle(style: Theme.of(this).text.body1, child: child) | 68 new DefaultTextStyle(style: Theme.of(this).text.body1, child: child) |
| 72 ); | 69 ); |
| 73 } | 70 } |
| 74 | 71 |
| 75 } | 72 } |
| OLD | NEW |