setSystemUIOverlayStyle method

void setSystemUIOverlayStyle (SystemUiOverlayStyle style)

Specifies the style to use for the system overlays that are visible (if any).

This method will schedule the embedder update to be run in a microtask. Any subsequent calls to this method during the current event loop will overwrite the pending value, such that only the last specified value takes effect.

Call this API in code whose lifecycle matches that of the desired system UI styles. For instance, to change the system UI style on a new page, consider calling when pushing/popping a new PageRoute.

However, the AppBar widget automatically sets the system overlay style based on its AppBar.brightness, so configure that instead of calling this method directly. Likewise, do the same for CupertinoNavigationBar via CupertinoNavigationBar.backgroundColor.

If a particular style is not supported on the platform, selecting it will have no effect.

Sample Code

@override
Widget build(BuildContext context) {
  SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle.dark);
  return /* ... */;
}

Implementation

static void setSystemUIOverlayStyle(SystemUiOverlayStyle style) {
  assert(style != null);
  if (_pendingStyle != null) {
    // The microtask has already been queued; just update the pending value.
    _pendingStyle = style;
    return;
  }
  if (style == _latestStyle) {
    // Trivial success: no microtask has been queued and the given style is
    // already in effect, so no need to queue a microtask.
    return;
  }
  _pendingStyle = style;
  scheduleMicrotask(() {
    assert(_pendingStyle != null);
    if (_pendingStyle != _latestStyle) {
      SystemChannels.platform.invokeMethod(
        'SystemChrome.setSystemUIOverlayStyle',
        _pendingStyle._toMap(),
      );
      _latestStyle = _pendingStyle;
    }
    _pendingStyle = null;
  });
}