FractionalOffset class

An offset that's expressed as a fraction of a Size.

FractionalOffset(1.0, 0.0) represents the top right of the Size.

FractionalOffset(0.0, 1.0) represents the bottom left of the Size.

FractionalOffset(0.5, 2.0) represents a point half way across the Size, below the bottom of the rectangle by the height of the Size.

The FractionalOffset class specifies offsets in terms of a distance from the top left, regardless of the TextDirection.

Design discussion

FractionalOffset and Alignment are two different representations of the same information: the location within a rectangle relative to the size of the rectangle. The difference between the two classes is in the coordinate system they use to represent the location.

FractionalOffset uses a coordinate system with an origin in the top-left corner of the rectangle whereas Alignment uses a coordinate system with an origin in the center of the rectangle.

Historically, FractionalOffset predates Alignment. When we attempted to make a version of FractionalOffset that adapted to the TextDirection, we ran into difficulty because placing the origin in the top-left corner introduced a left-to-right bias that was hard to remove.

By placing the origin in the center, Alignment and AlignmentDirectional are able to use the same origin, which means we can use a linear function to resolve an AlignmentDirectional into an Alignment in both TextDirection.rtl and TextDirection.ltr.

Alignment is better for most purposes than FractionalOffset and should be used instead of FractionalOffset. We continue to implement FractionalOffset to support code that predates Alignment.

See also:

  • Alignment, which uses a coordinate system based on the center of the rectangle instead of the top left corner of the rectangle.
Inheritance
Annotations
  • @immutable

Constructors

FractionalOffset(double dx, double dy)
Creates a fractional offset. [...]
const
FractionalOffset.fromOffsetAndRect(Offset offset, Rect rect)
Creates a fractional offset from a specific offset and rectangle. [...]
factory
FractionalOffset.fromOffsetAndSize(Offset offset, Size size)
Creates a fractional offset from a specific offset and size. [...]
factory

Properties

dx double
The distance fraction in the horizontal direction. [...]
read-only
dy double
The distance fraction in the vertical direction. [...]
read-only
hashCode int
The hash code for this object. [...]
read-only, inherited
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited
x double
The distance fraction in the horizontal direction. [...]
final, inherited
y double
The distance fraction in the vertical direction. [...]
final, inherited

Methods

toString() String
Returns a string representation of this object.
override
add(AlignmentGeometry other) AlignmentGeometry
Returns the sum of two AlignmentGeometry objects. [...]
inherited
alongOffset(Offset other) Offset
Returns the offset that is this fraction in the direction of the given offset.
inherited
alongSize(Size other) Offset
Returns the offset that is this fraction within the given size.
inherited
inscribe(Size size, Rect rect) Rect
Returns a rect of the given size, aligned within given rect as specified by this alignment. [...]
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
inherited
resolve(TextDirection direction) Alignment
Convert this instance into an Alignment, which uses literal coordinates (the x coordinate being explicitly a distance from the left). [...]
inherited
withinRect(Rect rect) Offset
Returns the point that is this fraction within the given rect.
inherited

Operators

operator %(double other) FractionalOffset
Computes the remainder in each dimension by the given factor.
override
operator *(double other) FractionalOffset
Scales the Alignment in each dimension by the given factor.
override
operator +(Alignment other) Alignment
Returns the sum of two Alignments.
override
operator -(Alignment other) Alignment
Returns the difference between two Alignments.
override
operator /(double other) FractionalOffset
Divides the Alignment in each dimension by the given factor.
override
operator unary-() FractionalOffset
Returns the negation of the given Alignment.
override
operator ~/(double other) FractionalOffset
Integer divides the Alignment in each dimension by the given factor.
override
operator ==(dynamic other) bool
The equality operator. [...]
inherited

Static Methods

lerp(FractionalOffset a, FractionalOffset b, double t) FractionalOffset
Linearly interpolate between two FractionalOffsets. [...]
override

Constants

bottomCenter → const FractionalOffset
The center point along the bottom edge.
const FractionalOffset(0.5, 1.0)
bottomLeft → const FractionalOffset
The bottom left corner.
const FractionalOffset(0.0, 1.0)
bottomRight → const FractionalOffset
The bottom right corner.
const FractionalOffset(1.0, 1.0)
center → const FractionalOffset
The center point, both horizontally and vertically.
const FractionalOffset(0.5, 0.5)
centerLeft → const FractionalOffset
The center point along the left edge.
const FractionalOffset(0.0, 0.5)
centerRight → const FractionalOffset
The center point along the right edge.
const FractionalOffset(1.0, 0.5)
topCenter → const FractionalOffset
The center point along the top edge.
const FractionalOffset(0.5, 0.0)
topLeft → const FractionalOffset
The top left corner.
const FractionalOffset(0.0, 0.0)
topRight → const FractionalOffset
The top right corner.
const FractionalOffset(1.0, 0.0)