onActivityChanged property

Stream<bool> get onActivityChanged

Returns a stream broadcasting the application's active status changes.

Implementation

Stream<bool> get onActivityChanged {
  if (_activityController != null) {
    return _activityController!.stream;
  }

  StreamSubscription? focusSubscription;

  _activityController = StreamController<bool>.broadcast(
    onListen: () {
      focusSubscription = onFocusChanged.listen((focused) {
        if (focused) {
          keepActive();
        } else {
          keepActive(false);
        }
      });
    },
    onCancel: () {
      focusSubscription?.cancel();
      _activityController?.close();
      _activityController = null;
    },
  );

  return _activityController!.stream;
}