ViewPort class abstract
Describes a rendering area size.
It is the central abstraction of the library which provides a simple interface to the viewport information and designed mainly for widgets which are sized relatively to the available rendering area, which is usually retrieved using MediaQuery.of. So main use case of the library is to replace all MediaQueryData.size calls with ViewPort.width and ViewPort.height. This allows for easy reuse of such widgets on web and desktop if they were initially designed for mobile apps.
The width property describe the available width, height - available height, and aspectRatio - relation of the width to the height.
ViewPort.of provides an access to the ViewPort configured using
ViewPortWidget InheritedWidget and follows the typical convention of
convention to retrieve the data associated with the widget that was found
in the tree. Example:
EmailTextField(width: ViewPort.of(context).width * 0.66)
See also:
- ViewPortWidget - InheritedWidget that holds a configuration of a ViewPort using a WidgetViewPortFactory (factory is necessary to provide a computation of the viewport instead of tree rebuild on every MediaQuery rebuild which will be a dependency of this ViewPortWidget instance in the most cases)
- ViewPorts - collection of the most regular ViewPort compositions
- FixedViewPort - provides a statically defined width and height values
- MediaQuerySizeViewPort - ViewPort adapter for a MediaQueryData instance, which usually will be used in a composition with other ViewPort implementations which will dynamically define the resulting width and height values
- MinimalOfViewPort - takes two ViewPort instances and chooses the minimal width and height
- MaximalOfViewPort - takes two ViewPort instances and chooses the maximal width and height
Constructors
- ViewPort()
Properties
- aspectRatio → double
-
width / height ratio.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- height → double
-
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- width → double
-
no setter
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
of(
BuildContext context) → ViewPort