N Kaushik

Flutter EdgeInsets class constructors

October 06, 2021

Flutter EdgeInsets class constructors:

EdgeInsets class is used to create offsets in the four directions: left, top, right and bottom. This offsets are immutable.

EdgeInsets class provides 5 different constructors to set the values.

EdgeInsets.all:

EdgeInsets.all is defined as like below:

const EdgeInsets.all(double value)

It creates insets with equal offsets. For example,

EdgeInsets.all(6.0)

This will assign 6.0 to all top, bottom, left and right.

EdgeInsets.fromLTRB:

EdgeInsets.fromLTRB is defined as like below:

const EdgeInsets.fromLTRB(double left, double top, double right, double bottom) 

It creates insets from offsets from left, top, right and bottom.

EdgeInsets.fromWindowPadding:

EdgeInsets.fromWindowPadding is defined as like below:

EdgeInsets.fromWindowPadding(WindowPadding padding, double devicePixelRatio) 

It is used to create insets using window padding.

The values are calculated like padding.left / devicePixelRatio, padding.right / devicePixelRatio etc.

EdgeInsets.only:

EdgeInsets.only is defined as like below:

const EdgeInsets.only({double left, double top, double right, double bottom}) 

We can provide specific values by using this constructor. For example,

const EdgeInsets.only(right: 10.0)

It will create indent only for right indent.

EdgeInsets.symmetric:

EdgeInsets.symmetric is used to create insets with symmetrical vertical and horizontal offset.

For example,

EdgeInsets.symmetric(horizontal: 2.0)

It will add only horizontal margin for left and right side. It will not add any vertical mergin.


Subscribe to my Newsletter

© 2021, nkaushik