# FractionalOffset class Null safety

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.

• 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
The distance fraction in the horizontal direction. [...]
dy
The distance fraction in the vertical direction. [...]
hashCode int
The hash code for this object. [...]
runtimeType Type
A representation of the runtime type of the object.
x
The distance fraction in the horizontal direction. [...]
final, inherited
y
The distance fraction in the vertical direction. [...]
final, inherited

## Methods

Returns the sum of two AlignmentGeometry objects. [...]
inherited
alongOffset(Offset other)
Returns the offset that is this fraction in the direction of the given offset.
inherited
alongSize(Size other)
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( direction)
Convert this instance into an Alignment, which uses literal coordinates (the `x` coordinate being explicitly a distance from the left). [...]
inherited
toString()
Returns a string representation of this object.
override
withinRect(Rect rect)
Returns the point that is this fraction within the given rect.
inherited

## Operators

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

## Static Methods

lerp()
Linearly interpolate between two FractionalOffsets. [...]
override

## Constants

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