DeviceOrientationBuilder class
Builds a widget tree that can depend on the device's orientation.
The orientation is obtained from MediaQuery.orientationOf, which reflects the actual device orientation as reported by the platform. This ensures consistency with MediaQueryData.orientation and correct behavior on foldable devices and other scenarios where the device orientation may differ from layout dimensions.
This is different from OrientationBuilder, which determines orientation based on the parent widget's layout constraints (width vs height), not the device's physical orientation.
This example shows how to use DeviceOrientationBuilder to display
different widgets based on the device orientation.
link
DeviceOrientationBuilder(
builder: (BuildContext context, Orientation orientation) {
return Text(orientation == Orientation.portrait
? 'Device is in Portrait'
: 'Device is in Landscape');
},
)
This widget requires a MediaQuery ancestor to obtain the orientation. Typically, this is provided by MaterialApp or WidgetsApp.
See also:
- OrientationBuilder, which builds based on parent widget's layout constraints rather than device orientation.
- MediaQueryData.orientation, which provides the device orientation directly from MediaQuery.
- LayoutBuilder, which exposes the complete layout constraints.
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatelessWidget
- DeviceOrientationBuilder
Constructors
- DeviceOrientationBuilder({Key? key, required OrientationWidgetBuilder builder})
-
Creates a device orientation builder.
const
Properties
- builder → OrientationWidgetBuilder
-
Builds the widgets below this widget given the device's orientation.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
build(
BuildContext context) → Widget -
Describes the part of the user interface represented by this widget.
override
-
createElement(
) → StatelessElement -
Creates a StatelessElement to manage this widget's location in the tree.
inherited
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited