didChangeLocales method

  1. @mustCallSuper
  2. @override
void didChangeLocales(
  1. List<Locale>? locales
)
inherited

Called when the system tells the app that the user's locale has changed. For example, if the user changes the system language settings.

Implementation

@mustCallSuper
@override
void didChangeLocales(List<Locale>? locales) {
  // A triggered system event
  _hadSystemEvent = true;

  // Don't if the State object is defunct.
  if (!mounted) {
    return;
  }

  ///
  /// This method exposes notifications from [Window.onLocaleChanged].

  /// No 'setState()' functions are allowed to fully function at this point.
//    _setStateAllowed = false;

  for (final con in controllerList) {
    con.didChangeLocales(locales);
  }

  _setStateAllowed = true;

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

  // Record the triggered event
  assert(() {
    if (_printEvents) {
      debugPrint('============ Event: didChangeLocales() in $this');
    }
    return true;
  }());
}