didChangeMetrics method
Called when the application's dimensions change. For example, when a phone is rotated.
Implementation
@override
@mustCallSuper
void didChangeMetrics() {
/// In general, this is not overridden often as the layout system takes care of
/// automatically recomputing the application geometry when the application
/// size changes
///
/// This method exposes notifications from [Window.onMetricsChanged].
/// See sample code below. No need to call super if you override.
/// @override
/// void didChangeMetrics() {
/// setState(() { _lastSize = ui.window.physicalSize; });
/// }
// A triggered system event
_hadSystemEvent = true;
// Don't if the State object is defunct.
if (!mounted) {
return;
}
/// No 'setState()' functions are allowed to fully function at this point.
_setStateAllowed = false;
for (final con in controllerList) {
con.didChangeMetrics();
}
_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: didChangeMetrics() in $this');
}
return true;
}());
}