Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1298)

Unified Diff: sky/sdk/lib/widgets/material.dart

Issue 1233703003: add initState, rename animated_container (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: remove print statement Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sky/sdk/lib/widgets/material.dart
diff --git a/sky/sdk/lib/widgets/material.dart b/sky/sdk/lib/widgets/material.dart
index cb24a8dd0a81fe1deba064097e92b5f5e3fea8f7..d8f6c9952c7c2bcc6fd6db706251343330838037 100644
--- a/sky/sdk/lib/widgets/material.dart
+++ b/sky/sdk/lib/widgets/material.dart
@@ -5,7 +5,7 @@
import '../animation/animation_performance.dart';
import '../painting/box_painter.dart';
import 'animated_component.dart';
-import 'animated_container.dart';
+import 'animation_builder.dart';
import 'basic.dart';
import 'default_text_style.dart';
import 'theme.dart';
@@ -27,29 +27,44 @@ class Material extends AnimatedComponent {
Material({
String key,
this.child,
- MaterialType type: MaterialType.card,
- int level: 0,
- Color color: null
+ this.type: MaterialType.card,
+ this.level: 0,
+ this.color
}) : super(key: key) {
- if (level == null) level = 0;
- _container = new AnimatedContainer()
+ assert(level != null);
+ }
+
+ Widget child;
+ MaterialType type;
+ int level;
+ Color color;
+
+ AnimationBuilder _builder;
+
+ void initState() {
+ _builder = new AnimationBuilder()
..shadow = new AnimatedType<double>(level.toDouble())
..backgroundColor = _getBackgroundColor(type, color)
..borderRadius = edges[type]
..shape = type == MaterialType.circle ? Shape.circle : Shape.rectangle;
- watchPerformance(_container.createPerformance(
- [_container.shadow], duration: _kAnimateShadowDuration));
- watchPerformance(_container.createPerformance(
- [_container.backgroundColor], duration: _kAnimateColorDuration));
+ watchPerformance(_builder.createPerformance(
+ [_builder.shadow], duration: _kAnimateShadowDuration));
+ watchPerformance(_builder.createPerformance(
+ [_builder.backgroundColor], duration: _kAnimateColorDuration));
+ super.initState();
}
- Widget child;
-
- AnimatedContainer _container;
-
void syncFields(Material source) {
child = source.child;
- _container.syncFields(source._container);
+ type = source.type;
+ level = source.level;
+ color = source.color;
+ _builder.updateFields(
+ shadow: new AnimatedType<double>(level.toDouble()),
+ backgroundColor: _getBackgroundColor(type, color),
+ borderRadius: edges[type],
+ shape: type == MaterialType.circle ? Shape.circle : Shape.rectangle
+ );
Matt Perry 2015/07/13 17:37:45 It's unfortunate the amount of boilerplate this ad
super.syncFields(source);
}
@@ -70,7 +85,7 @@ class Material extends AnimatedComponent {
}
Widget build() {
- return _container.build(
+ return _builder.build(
new DefaultTextStyle(style: Theme.of(this).text.body1, child: child)
);
}

Powered by Google App Engine
This is Rietveld 408576698