Skip to content

Commit b0aa502

Browse files
authored
Use curly_braces_in_flow_control_structures for animations, cupertino (#104612)
* Use `curly_braces_in_flow_control_structures` for `animation` * Use `curly_braces_in_flow_control_structures` for `cupertino` * fix comments
1 parent 9cc72df commit b0aa502

30 files changed

+349
-182
lines changed

packages/flutter/lib/src/animation/animation_controller.dart

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -389,8 +389,9 @@ class AnimationController extends Animation<double>
389389
/// If [isAnimating] is false, then [value] is not changing and the rate of
390390
/// change is zero.
391391
double get velocity {
392-
if (!isAnimating)
392+
if (!isAnimating) {
393393
return 0.0;
394+
}
394395
return _simulation!.dx(lastElapsedDuration!.inMicroseconds.toDouble() / Duration.microsecondsPerSecond);
395396
}
396397

@@ -456,8 +457,9 @@ class AnimationController extends Animation<double>
456457
'AnimationController methods should not be used after calling dispose.',
457458
);
458459
_direction = _AnimationDirection.forward;
459-
if (from != null)
460+
if (from != null) {
460461
value = from;
462+
}
461463
return _animateToInternal(upperBound);
462464
}
463465

@@ -489,8 +491,9 @@ class AnimationController extends Animation<double>
489491
'AnimationController methods should not be used after calling dispose.',
490492
);
491493
_direction = _AnimationDirection.reverse;
492-
if (from != null)
494+
if (from != null) {
493495
value = from;
496+
}
494497
return _animateToInternal(lowerBound);
495498
}
496499

@@ -856,12 +859,13 @@ class _InterpolationSimulation extends Simulation {
856859
@override
857860
double x(double timeInSeconds) {
858861
final double t = clampDouble(timeInSeconds / _durationInSeconds, 0.0, 1.0);
859-
if (t == 0.0)
862+
if (t == 0.0) {
860863
return _begin;
861-
else if (t == 1.0)
864+
} else if (t == 1.0) {
862865
return _end;
863-
else
866+
} else {
864867
return _begin + (_end - _begin) * _curve.transform(t);
868+
}
865869
}
866870

867871
@override

packages/flutter/lib/src/animation/animations.dart

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -188,22 +188,27 @@ class ProxyAnimation extends Animation<double>
188188
Animation<double>? get parent => _parent;
189189
Animation<double>? _parent;
190190
set parent(Animation<double>? value) {
191-
if (value == _parent)
191+
if (value == _parent) {
192192
return;
193+
}
193194
if (_parent != null) {
194195
_status = _parent!.status;
195196
_value = _parent!.value;
196-
if (isListening)
197+
if (isListening) {
197198
didStopListening();
199+
}
198200
}
199201
_parent = value;
200202
if (_parent != null) {
201-
if (isListening)
203+
if (isListening) {
202204
didStartListening();
203-
if (_value != _parent!.value)
205+
}
206+
if (_value != _parent!.value) {
204207
notifyListeners();
205-
if (_status != _parent!.status)
208+
}
209+
if (_status != _parent!.status) {
206210
notifyStatusListeners(_parent!.status);
211+
}
207212
_status = null;
208213
_value = null;
209214
}
@@ -233,8 +238,9 @@ class ProxyAnimation extends Animation<double>
233238

234239
@override
235240
String toString() {
236-
if (parent == null)
241+
if (parent == null) {
237242
return '${objectRuntimeType(this, 'ProxyAnimation')}(null; ${super.toStringDetails()} ${value.toStringAsFixed(3)})';
243+
}
238244
return '$parent\u27A9${objectRuntimeType(this, 'ProxyAnimation')}';
239245
}
240246
}
@@ -441,8 +447,9 @@ class CurvedAnimation extends Animation<double> with AnimationWithParentMixin<do
441447
final Curve? activeCurve = _useForwardCurve ? curve : reverseCurve;
442448

443449
final double t = parent.value;
444-
if (activeCurve == null)
450+
if (activeCurve == null) {
445451
return t;
452+
}
446453
if (t == 0.0 || t == 1.0) {
447454
assert(() {
448455
final double transformedValue = activeCurve.transform(t);
@@ -464,10 +471,12 @@ class CurvedAnimation extends Animation<double> with AnimationWithParentMixin<do
464471

465472
@override
466473
String toString() {
467-
if (reverseCurve == null)
474+
if (reverseCurve == null) {
468475
return '$parent\u27A9$curve';
469-
if (_useForwardCurve)
476+
}
477+
if (_useForwardCurve) {
470478
return '$parent\u27A9$curve\u2092\u2099/$reverseCurve';
479+
}
471480
return '$parent\u27A9$curve/$reverseCurve\u2092\u2099';
472481
}
473482
}
@@ -581,8 +590,9 @@ class TrainHoppingAnimation extends Animation<double>
581590
_lastValue = newValue;
582591
}
583592
assert(_lastValue != null);
584-
if (hop && onSwitchedTrain != null)
593+
if (hop && onSwitchedTrain != null) {
585594
onSwitchedTrain!();
595+
}
586596
}
587597

588598
@override
@@ -605,8 +615,9 @@ class TrainHoppingAnimation extends Animation<double>
605615

606616
@override
607617
String toString() {
608-
if (_nextTrain != null)
618+
if (_nextTrain != null) {
609619
return '$currentTrain\u27A9${objectRuntimeType(this, 'TrainHoppingAnimation')}(next: $_nextTrain)';
620+
}
610621
return '$currentTrain\u27A9${objectRuntimeType(this, 'TrainHoppingAnimation')}(no next)';
611622
}
612623
}
@@ -660,8 +671,9 @@ abstract class CompoundAnimation<T> extends Animation<T>
660671
/// Otherwise, default to [first].
661672
@override
662673
AnimationStatus get status {
663-
if (next.status == AnimationStatus.forward || next.status == AnimationStatus.reverse)
674+
if (next.status == AnimationStatus.forward || next.status == AnimationStatus.reverse) {
664675
return next.status;
676+
}
665677
return first.status;
666678
}
667679

packages/flutter/lib/src/animation/curves.dart

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,17 @@ class Interval extends Curve {
183183
assert(end <= 1.0);
184184
assert(end >= begin);
185185
t = clampDouble((t - begin) / (end - begin), 0.0, 1.0);
186-
if (t == 0.0 || t == 1.0)
186+
if (t == 0.0 || t == 1.0) {
187187
return t;
188+
}
188189
return curve.transform(t);
189190
}
190191

191192
@override
192193
String toString() {
193-
if (curve is! _Linear)
194+
if (curve is! _Linear) {
194195
return '${objectRuntimeType(this, 'Interval')}($begin\u22EF$end)\u27A9$curve';
196+
}
195197
return '${objectRuntimeType(this, 'Interval')}($begin\u22EF$end)';
196198
}
197199
}
@@ -348,12 +350,14 @@ class Cubic extends Curve {
348350
while (true) {
349351
final double midpoint = (start + end) / 2;
350352
final double estimate = _evaluateCubic(a, c, midpoint);
351-
if ((t - estimate).abs() < _cubicErrorBound)
353+
if ((t - estimate).abs() < _cubicErrorBound) {
352354
return _evaluateCubic(b, d, midpoint);
353-
if (estimate < t)
355+
}
356+
if (estimate < t) {
354357
start = midpoint;
355-
else
358+
} else {
356359
end = midpoint;
360+
}
357361
}
358362
}
359363

@@ -1219,10 +1223,11 @@ class _BounceInOutCurve extends Curve {
12191223

12201224
@override
12211225
double transformInternal(double t) {
1222-
if (t < 0.5)
1226+
if (t < 0.5) {
12231227
return (1.0 - _bounce(1.0 - t * 2.0)) * 0.5;
1224-
else
1228+
} else {
12251229
return _bounce(t * 2.0 - 1.0) * 0.5 + 0.5;
1230+
}
12261231
}
12271232
}
12281233

@@ -1304,10 +1309,11 @@ class ElasticInOutCurve extends Curve {
13041309
double transformInternal(double t) {
13051310
final double s = period / 4.0;
13061311
t = 2.0 * t - 1.0;
1307-
if (t < 0.0)
1312+
if (t < 0.0) {
13081313
return -0.5 * math.pow(2.0, 10.0 * t) * math.sin((t - s) * (math.pi * 2.0) / period);
1309-
else
1314+
} else {
13101315
return math.pow(2.0, -10.0 * t) * math.sin((t - s) * (math.pi * 2.0) / period) * 0.5 + 1.0;
1316+
}
13111317
}
13121318

13131319
@override

packages/flutter/lib/src/animation/listener_helpers.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ mixin AnimationLazyListenerMixin {
2626
@protected
2727
void didRegisterListener() {
2828
assert(_listenerCounter >= 0);
29-
if (_listenerCounter == 0)
29+
if (_listenerCounter == 0) {
3030
didStartListening();
31+
}
3132
_listenerCounter += 1;
3233
}
3334

@@ -41,8 +42,9 @@ mixin AnimationLazyListenerMixin {
4142
void didUnregisterListener() {
4243
assert(_listenerCounter >= 1);
4344
_listenerCounter -= 1;
44-
if (_listenerCounter == 0)
45+
if (_listenerCounter == 0) {
4546
didStopListening();
47+
}
4648
}
4749

4850
/// Called when the number of listeners changes from zero to one.
@@ -151,8 +153,9 @@ mixin AnimationLocalListenersMixin {
151153
return true;
152154
}());
153155
try {
154-
if (_listeners.contains(listener))
156+
if (_listeners.contains(listener)) {
155157
listener();
158+
}
156159
} catch (exception, stack) {
157160
FlutterError.reportError(FlutterErrorDetails(
158161
exception: exception,
@@ -229,8 +232,9 @@ mixin AnimationLocalStatusListenersMixin {
229232
final List<AnimationStatusListener> localListeners = _statusListeners.toList(growable: false);
230233
for (final AnimationStatusListener listener in localListeners) {
231234
try {
232-
if (_statusListeners.contains(listener))
235+
if (_statusListeners.contains(listener)) {
233236
listener(status);
237+
}
234238
} catch (exception, stack) {
235239
InformationCollector? collector;
236240
assert(() {

packages/flutter/lib/src/animation/tween.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,12 @@ class Tween<T extends Object?> extends Animatable<T> {
320320
/// subclass.
321321
@override
322322
T transform(double t) {
323-
if (t == 0.0)
323+
if (t == 0.0) {
324324
return begin as T;
325-
if (t == 1.0)
325+
}
326+
if (t == 1.0) {
326327
return end as T;
328+
}
327329
return lerp(t);
328330
}
329331

packages/flutter/lib/src/animation/tween_sequence.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ class TweenSequence<T> extends Animatable<T> {
5656
_items.addAll(items);
5757

5858
double totalWeight = 0.0;
59-
for (final TweenSequenceItem<T> item in _items)
59+
for (final TweenSequenceItem<T> item in _items) {
6060
totalWeight += item.weight;
61+
}
6162
assert(totalWeight > 0.0);
6263

6364
double start = 0.0;
@@ -80,11 +81,13 @@ class TweenSequence<T> extends Animatable<T> {
8081
@override
8182
T transform(double t) {
8283
assert(t >= 0.0 && t <= 1.0);
83-
if (t == 1.0)
84+
if (t == 1.0) {
8485
return _evaluateAt(t, _items.length - 1);
86+
}
8587
for (int index = 0; index < _items.length; index++) {
86-
if (_intervals[index].contains(t))
88+
if (_intervals[index].contains(t)) {
8789
return _evaluateAt(t, index);
90+
}
8891
}
8992
// Should be unreachable.
9093
throw StateError('TweenSequence.evaluate() could not find an interval for $t');

packages/flutter/lib/src/cupertino/activity_indicator.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,11 @@ class _CupertinoActivityIndicatorState extends State<CupertinoActivityIndicator>
107107
void didUpdateWidget(CupertinoActivityIndicator oldWidget) {
108108
super.didUpdateWidget(oldWidget);
109109
if (widget.animating != oldWidget.animating) {
110-
if (widget.animating)
110+
if (widget.animating) {
111111
_controller.repeat();
112-
else
112+
} else {
113113
_controller.stop();
114+
}
114115
}
115116
}
116117

packages/flutter/lib/src/cupertino/bottom_tab_bar.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,9 @@ class CupertinoTabBar extends StatelessWidget implements PreferredSizeWidget {
271271

272272
/// Change the active tab item's icon and title colors to active.
273273
Widget _wrapActiveItem(BuildContext context, Widget item, { required bool active }) {
274-
if (!active)
274+
if (!active) {
275275
return item;
276+
}
276277

277278
final Color activeColor = CupertinoDynamicColor.resolve(
278279
this.activeColor ?? CupertinoTheme.of(context).primaryColor,

packages/flutter/lib/src/cupertino/button.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,15 +214,17 @@ class _CupertinoButtonState extends State<CupertinoButton> with SingleTickerProv
214214
}
215215

216216
void _animate() {
217-
if (_animationController.isAnimating)
217+
if (_animationController.isAnimating) {
218218
return;
219+
}
219220
final bool wasHeldDown = _buttonHeldDown;
220221
final TickerFuture ticker = _buttonHeldDown
221222
? _animationController.animateTo(1.0, duration: kFadeOutDuration, curve: Curves.easeInOutCubicEmphasized)
222223
: _animationController.animateTo(0.0, duration: kFadeInDuration, curve: Curves.easeOutCubic);
223224
ticker.then<void>((void value) {
224-
if (mounted && wasHeldDown != _buttonHeldDown)
225+
if (mounted && wasHeldDown != _buttonHeldDown) {
225226
_animate();
227+
}
226228
});
227229
}
228230

0 commit comments

Comments
 (0)