Skip to content

Commit a0248eb

Browse files
authored
Use curly_braces_in_flow_control_structures for services, scheduler, semantics (#104616)
1 parent e71eb18 commit a0248eb

30 files changed

+443
-224
lines changed

packages/flutter/lib/src/scheduler/binding.dart

Lines changed: 55 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ double _timeDilation = 1.0;
2525
/// It is safe to set this before initializing the binding.
2626
set timeDilation(double value) {
2727
assert(value > 0.0);
28-
if (_timeDilation == value)
28+
if (_timeDilation == value) {
2929
return;
30+
}
3031
// If the binding has been created, we need to resetEpoch first so that we
3132
// capture start of the epoch with the current time dilation.
3233
SchedulerBinding._instance?.resetEpoch();
@@ -409,16 +410,18 @@ mixin SchedulerBinding on BindingBase {
409410
flow,
410411
);
411412
_taskQueue.add(entry);
412-
if (isFirstTask && !locked)
413+
if (isFirstTask && !locked) {
413414
_ensureEventLoopCallback();
415+
}
414416
return entry.completer.future;
415417
}
416418

417419
@override
418420
void unlocked() {
419421
super.unlocked();
420-
if (_taskQueue.isNotEmpty)
422+
if (_taskQueue.isNotEmpty) {
421423
_ensureEventLoopCallback();
424+
}
422425
}
423426

424427
// Whether this scheduler already requested to be called from the event loop.
@@ -429,17 +432,19 @@ mixin SchedulerBinding on BindingBase {
429432
void _ensureEventLoopCallback() {
430433
assert(!locked);
431434
assert(_taskQueue.isNotEmpty);
432-
if (_hasRequestedAnEventLoopCallback)
435+
if (_hasRequestedAnEventLoopCallback) {
433436
return;
437+
}
434438
_hasRequestedAnEventLoopCallback = true;
435439
Timer.run(_runTasks);
436440
}
437441

438442
// Scheduled by _ensureEventLoopCallback.
439443
void _runTasks() {
440444
_hasRequestedAnEventLoopCallback = false;
441-
if (handleEventLoopCallback())
442-
_ensureEventLoopCallback(); // runs next task when there's time
445+
if (handleEventLoopCallback()) {
446+
_ensureEventLoopCallback();
447+
} // runs next task when there's time
443448
}
444449

445450
/// Execute the highest-priority task, if it is of a high enough priority.
@@ -455,8 +460,9 @@ mixin SchedulerBinding on BindingBase {
455460
@visibleForTesting
456461
@pragma('vm:notify-debugger-on-exception')
457462
bool handleEventLoopCallback() {
458-
if (_taskQueue.isEmpty || locked)
463+
if (_taskQueue.isEmpty || locked) {
459464
return false;
465+
}
460466
final _TaskEntry<dynamic> entry = _taskQueue.first;
461467
if (schedulingStrategy(priority: entry.priority, scheduler: this)) {
462468
try {
@@ -690,8 +696,9 @@ mixin SchedulerBinding on BindingBase {
690696
/// off.
691697
Future<void> get endOfFrame {
692698
if (_nextFrameCompleter == null) {
693-
if (schedulerPhase == SchedulerPhase.idle)
699+
if (schedulerPhase == SchedulerPhase.idle) {
694700
scheduleFrame();
701+
}
695702
_nextFrameCompleter = Completer<void>();
696703
addPostFrameCallback((Duration timeStamp) {
697704
_nextFrameCompleter!.complete();
@@ -716,11 +723,13 @@ mixin SchedulerBinding on BindingBase {
716723

717724
bool _framesEnabled = true;
718725
void _setFramesEnabledState(bool enabled) {
719-
if (_framesEnabled == enabled)
726+
if (_framesEnabled == enabled) {
720727
return;
728+
}
721729
_framesEnabled = enabled;
722-
if (enabled)
730+
if (enabled) {
723731
scheduleFrame();
732+
}
724733
}
725734

726735
/// Ensures callbacks for [PlatformDispatcher.onBeginFrame] and
@@ -785,11 +794,13 @@ mixin SchedulerBinding on BindingBase {
785794
/// * [scheduleWarmUpFrame], which ignores the "Vsync" signal entirely and
786795
/// triggers a frame immediately.
787796
void scheduleFrame() {
788-
if (_hasScheduledFrame || !framesEnabled)
797+
if (_hasScheduledFrame || !framesEnabled) {
789798
return;
799+
}
790800
assert(() {
791-
if (debugPrintScheduleFrameStacks)
801+
if (debugPrintScheduleFrameStacks) {
792802
debugPrintStack(label: 'scheduleFrame() called. Current phase is $schedulerPhase.');
803+
}
793804
return true;
794805
}());
795806
ensureFrameCallbacksRegistered();
@@ -818,11 +829,13 @@ mixin SchedulerBinding on BindingBase {
818829
/// Consider using [scheduleWarmUpFrame] instead if the goal is to update the
819830
/// rendering as soon as possible (e.g. at application startup).
820831
void scheduleForcedFrame() {
821-
if (_hasScheduledFrame)
832+
if (_hasScheduledFrame) {
822833
return;
834+
}
823835
assert(() {
824-
if (debugPrintScheduleFrameStacks)
836+
if (debugPrintScheduleFrameStacks) {
825837
debugPrintStack(label: 'scheduleForcedFrame() called. Current phase is $schedulerPhase.');
838+
}
826839
return true;
827840
}());
828841
ensureFrameCallbacksRegistered();
@@ -848,8 +861,9 @@ mixin SchedulerBinding on BindingBase {
848861
///
849862
/// Prefer [scheduleFrame] to update the display in normal operation.
850863
void scheduleWarmUpFrame() {
851-
if (_warmUpFrame || schedulerPhase != SchedulerPhase.idle)
864+
if (_warmUpFrame || schedulerPhase != SchedulerPhase.idle) {
852865
return;
866+
}
853867

854868
_warmUpFrame = true;
855869
final TimelineTask timelineTask = TimelineTask()..start('Warm-up frame');
@@ -872,8 +886,9 @@ mixin SchedulerBinding on BindingBase {
872886
// then skipping every frame and finishing in the new time.
873887
resetEpoch();
874888
_warmUpFrame = false;
875-
if (hadScheduledFrame)
889+
if (hadScheduledFrame) {
876890
scheduleFrame();
891+
}
877892
});
878893

879894
// Lock events so touch events etc don't insert themselves until the
@@ -1026,8 +1041,9 @@ mixin SchedulerBinding on BindingBase {
10261041
_frameTimelineTask?.start('Frame');
10271042
_firstRawTimeStampInEpoch ??= rawTimeStamp;
10281043
_currentFrameTimeStamp = _adjustForEpoch(rawTimeStamp ?? _lastRawTimeStamp);
1029-
if (rawTimeStamp != null)
1044+
if (rawTimeStamp != null) {
10301045
_lastRawTimeStamp = rawTimeStamp;
1046+
}
10311047

10321048
assert(() {
10331049
_debugFrameNumber += 1;
@@ -1040,8 +1056,9 @@ mixin SchedulerBinding on BindingBase {
10401056
frameTimeStampDescription.write('(warm-up frame)');
10411057
}
10421058
_debugBanner = '▄▄▄▄▄▄▄▄ Frame ${_debugFrameNumber.toString().padRight(7)} ${frameTimeStampDescription.toString().padLeft(18)} ▄▄▄▄▄▄▄▄';
1043-
if (debugPrintBeginFrameBanner)
1059+
if (debugPrintBeginFrameBanner) {
10441060
debugPrint(_debugBanner);
1061+
}
10451062
}
10461063
return true;
10471064
}());
@@ -1055,8 +1072,9 @@ mixin SchedulerBinding on BindingBase {
10551072
final Map<int, _FrameCallbackEntry> callbacks = _transientCallbacks;
10561073
_transientCallbacks = <int, _FrameCallbackEntry>{};
10571074
callbacks.forEach((int id, _FrameCallbackEntry callbackEntry) {
1058-
if (!_removedIds.contains(id))
1075+
if (!_removedIds.contains(id)) {
10591076
_invokeFrameCallback(callbackEntry.callback, _currentFrameTimeStamp!, callbackEntry.debugStack);
1077+
}
10601078
});
10611079
_removedIds.clear();
10621080
} finally {
@@ -1079,22 +1097,25 @@ mixin SchedulerBinding on BindingBase {
10791097
try {
10801098
// PERSISTENT FRAME CALLBACKS
10811099
_schedulerPhase = SchedulerPhase.persistentCallbacks;
1082-
for (final FrameCallback callback in _persistentCallbacks)
1100+
for (final FrameCallback callback in _persistentCallbacks) {
10831101
_invokeFrameCallback(callback, _currentFrameTimeStamp!);
1102+
}
10841103

10851104
// POST-FRAME CALLBACKS
10861105
_schedulerPhase = SchedulerPhase.postFrameCallbacks;
10871106
final List<FrameCallback> localPostFrameCallbacks =
10881107
List<FrameCallback>.of(_postFrameCallbacks);
10891108
_postFrameCallbacks.clear();
1090-
for (final FrameCallback callback in localPostFrameCallbacks)
1109+
for (final FrameCallback callback in localPostFrameCallbacks) {
10911110
_invokeFrameCallback(callback, _currentFrameTimeStamp!);
1111+
}
10921112
} finally {
10931113
_schedulerPhase = SchedulerPhase.idle;
10941114
_frameTimelineTask?.finish(); // end the Frame
10951115
assert(() {
1096-
if (debugPrintEndFrameBanner)
1116+
if (debugPrintEndFrameBanner) {
10971117
debugPrint('▀' * _debugBanner!.length);
1118+
}
10981119
_debugBanner = null;
10991120
return true;
11001121
}());
@@ -1114,18 +1135,23 @@ mixin SchedulerBinding on BindingBase {
11141135
}
11151136

11161137
static void _debugDescribeTimeStamp(Duration timeStamp, StringBuffer buffer) {
1117-
if (timeStamp.inDays > 0)
1138+
if (timeStamp.inDays > 0) {
11181139
buffer.write('${timeStamp.inDays}d ');
1119-
if (timeStamp.inHours > 0)
1140+
}
1141+
if (timeStamp.inHours > 0) {
11201142
buffer.write('${timeStamp.inHours - timeStamp.inDays * Duration.hoursPerDay}h ');
1121-
if (timeStamp.inMinutes > 0)
1143+
}
1144+
if (timeStamp.inMinutes > 0) {
11221145
buffer.write('${timeStamp.inMinutes - timeStamp.inHours * Duration.minutesPerHour}m ');
1123-
if (timeStamp.inSeconds > 0)
1146+
}
1147+
if (timeStamp.inSeconds > 0) {
11241148
buffer.write('${timeStamp.inSeconds - timeStamp.inMinutes * Duration.secondsPerMinute}s ');
1149+
}
11251150
buffer.write('${timeStamp.inMilliseconds - timeStamp.inSeconds * Duration.millisecondsPerSecond}');
11261151
final int microseconds = timeStamp.inMicroseconds - timeStamp.inMilliseconds * Duration.microsecondsPerMillisecond;
1127-
if (microseconds > 0)
1152+
if (microseconds > 0) {
11281153
buffer.write('.${microseconds.toString().padLeft(3, "0")}');
1154+
}
11291155
buffer.write('ms');
11301156
}
11311157

@@ -1175,7 +1201,8 @@ mixin SchedulerBinding on BindingBase {
11751201
/// a [Priority] of [Priority.animation] or higher. Otherwise, runs
11761202
/// all tasks.
11771203
bool defaultSchedulingStrategy({ required int priority, required SchedulerBinding scheduler }) {
1178-
if (scheduler.transientCallbackCount > 0)
1204+
if (scheduler.transientCallbackCount > 0) {
11791205
return priority >= Priority.animation.value;
1206+
}
11801207
return true;
11811208
}

packages/flutter/lib/src/scheduler/ticker.dart

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ class Ticker {
8888
/// created the [Ticker] (typically a [TickerProvider]), not the object that
8989
/// listens to the ticker's ticks.
9090
set muted(bool value) {
91-
if (value == muted)
91+
if (value == muted) {
9292
return;
93+
}
9394
_muted = value;
9495
if (value) {
9596
unscheduleTick();
@@ -109,14 +110,18 @@ class Ticker {
109110
/// that indicates the application is not currently visible (e.g. if the
110111
/// device's screen is turned off).
111112
bool get isTicking {
112-
if (_future == null)
113+
if (_future == null) {
113114
return false;
114-
if (muted)
115+
}
116+
if (muted) {
115117
return false;
116-
if (SchedulerBinding.instance.framesEnabled)
118+
}
119+
if (SchedulerBinding.instance.framesEnabled) {
117120
return true;
118-
if (SchedulerBinding.instance.schedulerPhase != SchedulerPhase.idle)
119-
return true; // for example, we might be in a warm-up frame or forced frame
121+
}
122+
if (SchedulerBinding.instance.schedulerPhase != SchedulerPhase.idle) {
123+
return true;
124+
} // for example, we might be in a warm-up frame or forced frame
120125
return false;
121126
}
122127

@@ -162,8 +167,9 @@ class Ticker {
162167
scheduleTick();
163168
}
164169
if (SchedulerBinding.instance.schedulerPhase.index > SchedulerPhase.idle.index &&
165-
SchedulerBinding.instance.schedulerPhase.index < SchedulerPhase.postFrameCallbacks.index)
170+
SchedulerBinding.instance.schedulerPhase.index < SchedulerPhase.postFrameCallbacks.index) {
166171
_startTime = SchedulerBinding.instance.currentFrameTimeStamp;
172+
}
167173
return _future!;
168174
}
169175

@@ -189,8 +195,9 @@ class Ticker {
189195
/// By convention, this method is used by the object that receives the ticks
190196
/// (as opposed to the [TickerProvider] which created the ticker).
191197
void stop({ bool canceled = false }) {
192-
if (!isActive)
198+
if (!isActive) {
193199
return;
200+
}
194201

195202
// We take the _future into a local variable so that isTicking is false
196203
// when we actually complete the future (isTicking uses _future to
@@ -239,8 +246,9 @@ class Ticker {
239246

240247
// The onTick callback may have scheduled another tick already, for
241248
// example by calling stop then start again.
242-
if (shouldScheduleTick)
249+
if (shouldScheduleTick) {
243250
scheduleTick(rescheduling: true);
251+
}
244252
}
245253

246254
/// Schedules a tick for the next frame.
@@ -286,8 +294,9 @@ class Ticker {
286294
if (originalTicker._future != null) {
287295
_future = originalTicker._future;
288296
_startTime = originalTicker._startTime;
289-
if (shouldScheduleTick)
297+
if (shouldScheduleTick) {
290298
scheduleTick();
299+
}
291300
originalTicker._future = null; // so that it doesn't get disposed when we dispose of originalTicker
292301
originalTicker.unscheduleTick();
293302
}
@@ -474,8 +483,9 @@ class TickerCanceled implements Exception {
474483

475484
@override
476485
String toString() {
477-
if (ticker != null)
486+
if (ticker != null) {
478487
return 'This ticker was canceled: $ticker';
488+
}
479489
return 'The ticker was canceled before the "orCancel" property was first used.';
480490
}
481491
}

packages/flutter/lib/src/semantics/binding.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ mixin SemanticsBinding on BindingBase {
6464
bool get disableAnimations {
6565
bool value = _accessibilityFeatures.disableAnimations;
6666
assert(() {
67-
if (debugSemanticsDisableAnimations != null)
67+
if (debugSemanticsDisableAnimations != null) {
6868
value = debugSemanticsDisableAnimations!;
69+
}
6970
return true;
7071
}());
7172
return value;

0 commit comments

Comments
 (0)