division
a flutter widget with the goal of simplifying styling and to reduce nesting, inspired by css
getting started wih the flutter widget
the division
widget has 3 properties. a style
property, a gesture
property and a child
property. as simple as that!
division(style: styleclass, gesture: gestureclass, child, widget);
simple example
import
import 'package:division/division.dart';
simple usage
division(
style: styleclass()
..width(200)
..height(100)
..backgroundcolor('#eeeeee')
..borderradius(all: 30.0)
..elevation(30)
..align('center')
..alignchild('center'),
gesture: gestureclass()
..ontap(() => print('widget pressed')),
child: text('some text'),
)
the result
style property
the style property expects a styleclass
which is a class holding all the styling for the flutter widget.
styleclass
to add a style to the styleclass
, use the ..[style] syntax. the two dots is used to not return [style], but the styleclass
align
..align(dynamic alignment)
align
parameters support [string] value (‘center’, ‘left’, ‘bottomright’…), [list<double>]
value ([dx, dy]), [double] value (same value for dx and dy) and [alignment].
align child
..alignchild(dynamic alignment)
align
parameters support [string] value (‘center’, ‘left’, ‘bottomright’…), [list<double>]
value ([dx, dy]), [double] value (same value for dx and dy) and [alignment].
padding
..padding({double all,
double horizontal,
double vertical,
double top,
double bottom,
double left,
double right})
if all
is defined, non of the other properties will have an effect.
if horizontal
and vertical
is defined, top
, bottom
, left
, and right
will have no effect.
margin
..margin({double all,
double horizontal,
double vertical,
double top,
double bottom,
double left,
double right})
if all
is defined, non of the other properties will have an effect.
if horizontal
and vertical
is defined, top
, bottom
, left
, and right
will have no effect.
background color
..backgroundcolor(dynamic color)
color
parameter supports hex (‘#xxxxxx’), rgb ([int, int, int]), rgba ([int, int, int, double]) and [color].
gradient
..lineargradient({dynamic beginalign = 'left',
dynamic endalign = 'right',
@required list<dynamic> colors,
tilemode tilemode = tilemode.clamp,
list<double> stops})
..radialgradient(
{dynamic centeralign = 'center',
double radius = 0.5,
@required list<dynamic> colors,
tilemode tilemode = tilemode.clamp,
list<double> stops})
..sweepgradient(
{dynamic centeralign = 'center',
double startangle = 0.0,
double endangle,
@required list<dynamic> colors,
tilemode tilemode = tilemode.clamp,
list<double> stops})
choose between 3 gradient variants.
sweepgradient()
by default does not use radians for the startangle
and the endangle
. by default 0.25 equals 45 degrees, 1 equals one full turn etc.
to change to use radians do: styleclass(useradians: true)..
.
color
parameter supports hex (‘#xxxxxx’), rgb ([int, int, int]), rgba ([int, int, int, double]) and [color].
align
parameters support [string] value (‘center’, ‘left’, ‘bottomright’…), [list<double>]
value ([dx, dy]), [double] value (same value for dx and dy) and [alignment].
border
..border(
{double all,
double left,
double right,
double top,
double bottom,
dynamic color = const color(0xff000000),
borderstyle style = borderstyle.solid})
choose between all
or left
, right
, top
and bottom
.
color
parameter supports hex (‘#xxxxxx’), rgb ([int, int, int]), rgba ([int, int, int, double]) and [color].
border radius
..borderradius(
{double all,
double topleft,
double topright,
double bottomleft,
double bottomright})
eigther use the all
property to apply to all corners, or user topleft
, topright
, bottomleft
and bottomright
.
if the all
property is defined, the other properties will have no effect.
box shadow
..boxshadow(
{dynamic color = const color(0x33000000),
double blur,
list<double> offset,
double spread})
color
parameter supports hex (‘#xxxxxx’), rgb ([int, int, int]), rgba ([int, int, int, double]) and [color].
if defined while the elevation property is defined, the last one defined will be the style applied.
offset
is given in the format [double dx, double dy]
elevation
..elevation(
double elevation,
{bool angled = false,
dynamic color = const color(0x33000000)})
elevates the flutter widget with a boxshadow.
if the elevation property is used at the same time as the boxshadow property, the last one
defined will be the applied style.
color
parameter supports hex (‘#xxxxxx’), rgb ([int, int, int]), rgba ([int, int, int, double]) and [color].
if the angled
property is true, the shadow will be att 45 degrees.
scale
..scale(double scale)
scale the flutter widget
offset
..offset([double dx, double dy])
offsets the flutter widget
rotate
..rotate(double rotate)
rotates the flutter widget
by default one turn equals 1. to change to radians: styleclass(useradians: true)..
ripple
material ripple effect
..ripple({bool enable = false, dynamic splashcolor, dynamic highlightcolor})
still a [beta] feature with known issues.
animate
..animate([int duration, curve curve = curves.linear])
animates the flutter widget when one of its style properties changes.
duration
is given in milliseconds.
i am considering to implement a only
parameter to choose to only animate certain properties.
add
..add(styleclass styleclass, {bool override = false})
adds a styleclass
to a styleclass
.
by default the added styleclass
does not override already set style. change override to true, to override already set style.
width, minwidth, maxwidth, height, minheight, maxheight
..[type](double length)
gesture property
the gesture property expects a gestureclass
which is a class holding all the gestures for the flutter widget.
gestureclass
to add a style to the gestureclass
, use the ..[gesture] syntax. the two dots is used to not return the [gesture], but the gestureclass
the gestureclass
takes all the same parameters as the gesturedetector
widget.
..[gesture](function)
child property
widget child
Comments are closed.