use conditional assignment (#9252)

This commit is contained in:
Alexandre Ardhuin
2017-04-07 21:41:17 +02:00
committed by GitHub
parent 3eb87830e9
commit 8bcf302e23
21 changed files with 30 additions and 84 deletions

View File

@@ -577,10 +577,8 @@ class BoxShadow {
static List<BoxShadow> lerpList(List<BoxShadow> a, List<BoxShadow> b, double t) {
if (a == null && b == null)
return null;
if (a == null)
a = <BoxShadow>[];
if (b == null)
b = <BoxShadow>[];
a ??= <BoxShadow>[];
b ??= <BoxShadow>[];
final List<BoxShadow> result = <BoxShadow>[];
final int commonLength = math.min(a.length, b.length);
for (int i = 0; i < commonLength; ++i)

View File

@@ -1482,8 +1482,7 @@ abstract class RenderBox extends RenderObject {
@mustCallSuper
double getDistanceToActualBaseline(TextBaseline baseline) {
assert(_debugDoingBaseline);
if (_cachedBaselines == null)
_cachedBaselines = <TextBaseline, double>{};
_cachedBaselines ??= <TextBaseline, double>{};
_cachedBaselines.putIfAbsent(baseline, () => computeDistanceToActualBaseline(baseline));
return _cachedBaselines[baseline];
}

View File

@@ -203,8 +203,7 @@ class ContainerLayer extends Layer {
if (_lastChild != null)
_lastChild._nextSibling = child;
_lastChild = child;
if (_firstChild == null)
_firstChild = child;
_firstChild ??= child;
}
void _remove(Layer child) {

View File

@@ -2697,8 +2697,7 @@ abstract class ContainerRenderObjectMixin<ChildType extends RenderObject, Parent
_firstChildParentData.previousSibling = child;
}
_firstChild = child;
if (_lastChild == null)
_lastChild = child;
_lastChild ??= child;
} else {
assert(_firstChild != null);
assert(_lastChild != null);

View File

@@ -199,8 +199,7 @@ class Ticker {
assert(scheduled);
_animationId = null;
if (_startTime == null)
_startTime = timeStamp;
_startTime ??= timeStamp;
_onTick(timeStamp - _startTime);

View File

@@ -132,8 +132,7 @@ class FocusScopeNode extends Object with TreeDiagnosticsMixin {
if (_firstChild != null)
_firstChild._previousSibling = child;
_firstChild = child;
if (_lastChild == null)
_lastChild = child;
_lastChild ??= child;
child._updateManager(_manager);
}

View File

@@ -24,8 +24,7 @@ class TestGestureFlutterBinding extends BindingBase with GestureBinding {
TestGestureFlutterBinding _binding = new TestGestureFlutterBinding();
void ensureTestGestureBinding() {
if (_binding == null)
_binding = new TestGestureFlutterBinding();
_binding ??= new TestGestureFlutterBinding();
assert(GestureBinding.instance != null);
}