didChangeAppLifecycleState method

  1. @protected
  2. @override
  3. @mustCallSuper
void didChangeAppLifecycleState(
  1. AppLifecycleState state
)
inherited

Called when the system puts the app in the background or returns the app to the foreground.

Implementation

@protected
@override
@mustCallSuper
void didChangeAppLifecycleState(AppLifecycleState state) {
  /// No 'setState()' functions are allowed to fully function at this point.
  _setStateAllowed = false;

  /// First, process the State object's own event functions.
  switch (state) {
    case AppLifecycleState.inactive:
      inactive = true;
      inactiveLifecycleState();
      break;
    case AppLifecycleState.paused:
      paused = true;
      pausedLifecycleState();
      break;
    case AppLifecycleState.detached:
      detached = true;
      detachedLifecycleState();
      break;
    case AppLifecycleState.resumed:
      resumed = true; // The StateX object now resumed will be re-created.
      resumedLifecycleState();
      break;
  }

  for (final con in _controllerList) {
    con.didChangeAppLifecycleState(state);
    switch (state) {
      case AppLifecycleState.inactive:
        con.inactiveLifecycleState();
        break;
      case AppLifecycleState.paused:
        con.pausedLifecycleState();
        break;
      case AppLifecycleState.detached:
        con.detachedLifecycleState();
        break;
      case AppLifecycleState.resumed:
        con.resumedLifecycleState();
        break;
    }
  }

  _setStateAllowed = true;

  if (_setStateRequested) {
    _setStateRequested = false;
    // Only the latest State is rebuilt
    if (isEndState) {
      /// Perform a 'rebuild' if requested.
      setState(() {});
    }
  }
}