@@ -25,8 +25,9 @@ double _timeDilation = 1.0;
2525/// It is safe to set this before initializing the binding.
2626set 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.
11771203bool 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}
0 commit comments