debugLockDelegate method

  1. @override
bool debugLockDelegate(
  1. BuildContext context
)
override

This is called by PlatformMenuBar when it is initialized, to be sure that only one is active at a time.

The debugLockDelegate function should be called before the first call to setMenus.

If the lock is successfully acquired, debugLockDelegate will return true.

If your implementation of a PlatformMenuDelegate can have only limited active instances, enforce it when you override this function.

See also:

Implementation

@override
bool debugLockDelegate(BuildContext context) {
  assert(() {
    // It's OK to lock if the lock isn't set, but not OK if a different
    // context is locking it.
    if (_lockedContext != null && _lockedContext != context) {
      return false;
    }
    _lockedContext = context;
    return true;
  }());
  return true;
}