debugDefaultTargetPlatformOverride top-level property
Override the defaultTargetPlatform in debug builds.
Setting this to null returns the defaultTargetPlatform to its original value (based on the actual current platform).
Generally speaking this override is only useful for tests. To change the platform that widgets resemble, consider using the platform override APIs (such as ThemeData.platform in the material library) instead.
Setting debugDefaultTargetPlatformOverride (as opposed to, say, ThemeData.platform) will cause unexpected and undesirable effects. For example, setting this to TargetPlatform.iOS when the application is running on Android will cause the TalkBack accessibility tool on Android to be confused because it would be receiving data intended for iOS VoiceOver. Similarly, setting it to TargetPlatform.android while on iOS will cause certainly widgets to work assuming the presence of a system-wide back button, which will make those widgets unusable since iOS has no such button.
Attempting to override this property in non-debug builds causes an error.
Implementation
TargetPlatform? get debugDefaultTargetPlatformOverride =>
_debugDefaultTargetPlatformOverride;
Implementation
set debugDefaultTargetPlatformOverride(TargetPlatform? value) {
if (!kDebugMode) {
throw FlutterError(
'Cannot modify debugDefaultTargetPlatformOverride in non-debug builds.');
}
_debugDefaultTargetPlatformOverride = value;
}