lockEvents method

  1. @protected
Future<void> lockEvents (Future<void> callback())
@protected

Locks the dispatching of asynchronous events and callbacks until the callback's future completes.

This causes input lag and should therefore be avoided when possible. It is primarily intended for use during non-user-interactive time such as to allow reassembleApplication to block input while it walks the tree (which it partially does asynchronously).

The Future returned by the callback argument is returned by lockEvents.

Implementation

@protected
Future<void> lockEvents(Future<void> callback()) {
  developer.Timeline.startSync('Lock events');

  assert(callback != null);
  _lockCount += 1;
  final Future<void> future = callback();
  assert(future != null, 'The lockEvents() callback returned null; it should return a Future<void> that completes when the lock is to expire.');
  future.whenComplete(() {
    _lockCount -= 1;
    if (!locked) {
      developer.Timeline.finishSync();
      unlocked();
    }
  });
  return future;
}