platform property

TargetPlatform platform

The platform the material widgets should adapt to target.

Defaults to the current platform, as exposed by defaultTargetPlatform. This should be used in order to style UI elements according to platform conventions.

Widgets from the material library should use this getter (via Theme.of) to determine the current platform for the purpose of emulating the platform behavior (e.g. scrolling or haptic effects). Widgets and render objects at lower layers that try to emulate the underlying platform platform can depend on defaultTargetPlatform directly, or may require that the target platform be provided as an argument. The object should only be used directly when it's critical to actually know the current platform, without any overrides possible (for example, when a system API is about to be called).

In a test environment, the platform returned is regardless of the host platform. (Android was chosen because the tests were originally written assuming Android-like behavior, and we added platform adaptations for other platforms later). Tests can check behavior for other platforms by setting the platform of the Theme explicitly to another TargetPlatform value, or by setting debugDefaultTargetPlatformOverride.


final TargetPlatform platform