Commit 52790aed authored by Adam Barth's avatar Adam Barth

Use null-aware operators in package:sky

parent 8df083df
...@@ -50,7 +50,7 @@ void updateTaskDescription(String label, Color color) { ...@@ -50,7 +50,7 @@ void updateTaskDescription(String label, Color color) {
TaskDescription description = new TaskDescription() TaskDescription description = new TaskDescription()
..label = label ..label = label
..primaryColor = (color != null ? color.value : null); ..primaryColor = color?.value;
_activityProxy.ptr.setTaskDescription(description); _activityProxy.ptr.setTaskDescription(description);
} }
......
...@@ -242,7 +242,7 @@ class OpacityLayer extends ContainerLayer { ...@@ -242,7 +242,7 @@ class OpacityLayer extends ContainerLayer {
int alpha; int alpha;
void addToScene(sky.SceneBuilder builder, Offset layerOffset) { void addToScene(sky.SceneBuilder builder, Offset layerOffset) {
builder.pushOpacity(alpha, bounds == null ? null : bounds.shift(layerOffset)); builder.pushOpacity(alpha, bounds?.shift(layerOffset));
addChildrenToScene(builder, offset + layerOffset); addChildrenToScene(builder, offset + layerOffset);
builder.pop(); builder.pop();
} }
......
...@@ -487,10 +487,7 @@ class Stack extends MultiChildRenderObjectWrapper { ...@@ -487,10 +487,7 @@ class Stack extends MultiChildRenderObjectWrapper {
RenderStack get renderObject => super.renderObject; RenderStack get renderObject => super.renderObject;
void updateParentData(RenderObject child, Positioned positioned) { void updateParentData(RenderObject child, Positioned positioned) {
if (positioned == null) _updateParentDataWithValues(child, positioned?.top, positioned?.right, positioned?.bottom, positioned?.left);
_updateParentDataWithValues(child, null, null, null, null);
else
_updateParentDataWithValues(child, positioned.top, positioned.right, positioned.bottom, positioned.left);
} }
void _updateParentDataWithValues(RenderObject child, double top, double right, double bottom, double left) { void _updateParentDataWithValues(RenderObject child, double top, double right, double bottom, double left) {
...@@ -592,7 +589,7 @@ class Flex extends MultiChildRenderObjectWrapper { ...@@ -592,7 +589,7 @@ class Flex extends MultiChildRenderObjectWrapper {
} }
void updateParentData(RenderObject child, Flexible flexible) { void updateParentData(RenderObject child, Flexible flexible) {
_updateParentDataWithValues(child, flexible == null ? null : flexible.flex); _updateParentDataWithValues(child, flexible?.flex);
} }
void _updateParentDataWithValues(RenderObject child, int flex) { void _updateParentDataWithValues(RenderObject child, int flex) {
......
...@@ -21,7 +21,7 @@ class DefaultTextStyle extends Inherited { ...@@ -21,7 +21,7 @@ class DefaultTextStyle extends Inherited {
static TextStyle of(Widget widget) { static TextStyle of(Widget widget) {
DefaultTextStyle result = widget.inheritedOfType(DefaultTextStyle); DefaultTextStyle result = widget.inheritedOfType(DefaultTextStyle);
return result == null ? null : result.style; return result?.style;
} }
bool syncShouldNotify(DefaultTextStyle old) => style != old.style; bool syncShouldNotify(DefaultTextStyle old) => style != old.style;
......
...@@ -498,7 +498,7 @@ abstract class TagNode extends Widget { ...@@ -498,7 +498,7 @@ abstract class TagNode extends Widget {
} }
void _sync(Widget old, dynamic slot) { void _sync(Widget old, dynamic slot) {
Widget oldChild = old == null ? null : (old as TagNode).child; Widget oldChild = (old as TagNode)?.child;
child = syncChild(child, oldChild, slot); child = syncChild(child, oldChild, slot);
if (child != null) { if (child != null) {
assert(child.parent == this); assert(child.parent == this);
...@@ -1259,7 +1259,7 @@ abstract class OneChildRenderObjectWrapper extends RenderObjectWrapper { ...@@ -1259,7 +1259,7 @@ abstract class OneChildRenderObjectWrapper extends RenderObjectWrapper {
void syncRenderObject(RenderObjectWrapper old) { void syncRenderObject(RenderObjectWrapper old) {
super.syncRenderObject(old); super.syncRenderObject(old);
Widget oldChild = old == null ? null : (old as OneChildRenderObjectWrapper).child; Widget oldChild = (old as OneChildRenderObjectWrapper)?.child;
Widget newChild = child; Widget newChild = child;
_child = syncChild(newChild, oldChild, null); _child = syncChild(newChild, oldChild, null);
assert((newChild == null && child == null) || (newChild != null && child.parent == this)); assert((newChild == null && child == null) || (newChild != null && child.parent == this));
...@@ -1304,7 +1304,7 @@ abstract class MultiChildRenderObjectWrapper extends RenderObjectWrapper { ...@@ -1304,7 +1304,7 @@ abstract class MultiChildRenderObjectWrapper extends RenderObjectWrapper {
void insertChildRenderObject(RenderObjectWrapper child, Widget slot) { void insertChildRenderObject(RenderObjectWrapper child, Widget slot) {
final renderObject = this.renderObject; // TODO(ianh): Remove this once the analyzer is cleverer final renderObject = this.renderObject; // TODO(ianh): Remove this once the analyzer is cleverer
RenderObject nextSibling = slot != null ? slot.renderObject : null; RenderObject nextSibling = slot?.renderObject;
assert(nextSibling == null || nextSibling is RenderObject); assert(nextSibling == null || nextSibling is RenderObject);
assert(renderObject is ContainerRenderObjectMixin); assert(renderObject is ContainerRenderObjectMixin);
renderObject.add(child.renderObject, before: nextSibling); renderObject.add(child.renderObject, before: nextSibling);
......
...@@ -65,7 +65,7 @@ class HomogeneousViewport extends RenderObjectWrapper { ...@@ -65,7 +65,7 @@ class HomogeneousViewport extends RenderObjectWrapper {
} }
void insertChildRenderObject(RenderObjectWrapper child, Widget slot) { void insertChildRenderObject(RenderObjectWrapper child, Widget slot) {
RenderObject nextSibling = slot != null ? slot.renderObject : null; RenderObject nextSibling = slot?.renderObject;
renderObject.add(child.renderObject, before: nextSibling); renderObject.add(child.renderObject, before: nextSibling);
} }
......
...@@ -31,7 +31,7 @@ class IconTheme extends Inherited { ...@@ -31,7 +31,7 @@ class IconTheme extends Inherited {
static IconThemeData of(Component component) { static IconThemeData of(Component component) {
IconTheme result = component.inheritedOfType(IconTheme); IconTheme result = component.inheritedOfType(IconTheme);
return result == null ? null : result.data; return result?.data;
} }
bool syncShouldNotify(IconTheme old) => data != old.data; bool syncShouldNotify(IconTheme old) => data != old.data;
......
...@@ -208,7 +208,7 @@ class Scaffold extends RenderObjectWrapper { ...@@ -208,7 +208,7 @@ class Scaffold extends RenderObjectWrapper {
} }
void insertChildRenderObject(RenderObjectWrapper child, ScaffoldSlots slot) { void insertChildRenderObject(RenderObjectWrapper child, ScaffoldSlots slot) {
renderObject[slot] = child != null ? child.renderObject : null; renderObject[slot] = child?.renderObject;
} }
void detachChildRenderObject(RenderObjectWrapper child) { void detachChildRenderObject(RenderObjectWrapper child) {
......
...@@ -11,8 +11,6 @@ import 'package:vector_math/vector_math.dart'; ...@@ -11,8 +11,6 @@ import 'package:vector_math/vector_math.dart';
export 'package:sky/animation/direction.dart' show Direction; export 'package:sky/animation/direction.dart' show Direction;
dynamic _maybe(AnimatedValue x) => x != null ? x.value : null;
// A helper class to anchor widgets to one another. Pass an instance of this to // A helper class to anchor widgets to one another. Pass an instance of this to
// a Transition, then use the build() method to create a child with the same // a Transition, then use the build() method to create a child with the same
// transition applied. // transition applied.
...@@ -270,7 +268,7 @@ class SquashTransition extends TransitionBase { ...@@ -270,7 +268,7 @@ class SquashTransition extends TransitionBase {
performance.updateVariable(width); performance.updateVariable(width);
if (height != null) if (height != null)
performance.updateVariable(height); performance.updateVariable(height);
return new SizedBox(width: _maybe(width), height: _maybe(height), child: child); return new SizedBox(width: width?.value, height: height?.value, child: child);
} }
} }
......
...@@ -15,4 +15,4 @@ dependencies: ...@@ -15,4 +15,4 @@ dependencies:
vector_math: ^1.4.3 vector_math: ^1.4.3
intl: ^0.12.4+2 intl: ^0.12.4+2
environment: environment:
sdk: '>=1.8.0 <2.0.0' sdk: '>=1.12.0 <2.0.0'
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment