A Flutter package that introduce the Length class and some related class like DynamicOffset. It mimics the css length unit and supports four unit including px, percentage, vw and vh. The user would need to supply the constraint length and the screen size in order to get a px value from the Length class.
Having a length unit in Flutter can ease the process of creating responsive apps. Also, all the classes in this package can be serialized and deserialized.
Create a Length instance:
var length=Length(10.0, unit: LengthUnit.percent)
Get the actual px value by calling:
double px=length.toPX(constraintSize: ???, screenSize: ???);
where the constraintSize you can get by using the LayoutBuilder and the screenSize you can get with MediaQuery.
You can also create Length instance from numbers. For example:
will create a Length instance with value 10 and unit px.
The DynamicOffset, DynamicRadius and DynamicBorderRadius classes are all using Length with the understanding that they will be provided with a Size and convert to the regular Flutter class Offset, Radius and BorderRadius classes.
var dynamicOffset=DynamicOffset(dx: 10.toPXLength, dy: 10.toPXLength); Offset offset=dynamicOffset.toOffset(Size size);