division 0.9.0 copy "division: ^0.9.0" to clipboard
division: ^0.9.0 copied to clipboard

Simple to use yet powerfull style widgets with syntax inspired by CSS.

Division #


Buy Me A Coffee

Simple to use yet powerfull style widgets with syntax inspired by CSS.

Please check out styled_widget which is a replacement of Division! #

The true power of this package is a combination of its features. Flutter widgets are designed to combine both the styling widgets and the structural widgets together when building apps. This package tries to decouple style from structure. This results in much more readable code. Another strong point of this package is the ease of animations.

⚠️ If you encounter an issue or have any feedback which you think could improve Division, please open an issue here

Built with Division #

App designer, Code Code

Getting Started #

This is the two main widgets included in Division

Parent(
  child: Widget,
  style: ParentStyle, 
  gesture: Gestures,
);
copied to clipboard
Txt(
  String,
  style: TxtStyle,
  gesture: Gestures,
);
copied to clipboard

Basic example #

Import

import 'package:division/division.dart';
copied to clipboard

Code

bool pressed = false;

final buttonStyle = (pressed) => TxtStyle()
  ..alignment.center()
  ..background.color(pressed ? Colors.orange : Colors.white)
  ..textColor(pressed ? Colors.white : Colors.orange)
  ..borderRadius(all: 5)
  ..border(all: 3, color: Colors.orange)
  ..padding(vertical: 10, horizontal: 15)
  ..ripple(true)
  ..animate(150, Curves.easeOut);

Gestures buttonGestures() =>
    Gestures()..isTap((isPressed) => setState(() => pressed = isPressed));

@override
Widget build(BuildContext context) {
  return Txt(
    'Styled button!',
    style: buttonStyle(pressed),
    gesture: buttonGestures(),
  );
}
copied to clipboard

Result

Documentation #

All current and future Division widgets share a common style base.

Core style methods #

Animate
..animate([int duration, Curve curve = Curves.linear])
copied to clipboard

A powerful style method. Whenever a style property changes, the widget will animate between the two states (given the style property is compatibel with animations). duration in ms

Alignment
..alignment.[alignment] // alignment.topCenter()
copied to clipboard

The widget alignment

Content alignment
..alignmentContent.[alignment] // alignment.topCenter()
copied to clipboard

Alignment of the child.

Padding
..padding({double all, 
      double horizontal, 
      double vertical, 
      double top, 
      double bottom, 
      double left, 
      double right})
copied to clipboard

All properties work together. padding(all: 10, top: 30) is equivilent to padding(top: 30, bottom: 10, left: 10, right: 10)

Margin
..margin({double all,
      double horizontal,
      double vertical,
      double top,
      double bottom,
      double left,
      double right})
copied to clipboard

All properties work together. margin(all: 10, top: 30) is equivilent to margin(top: 30, bottom: 10, left: 10, right: 10)

Background color
..background.color(Color)
..background.hex(xxxxxx)
..background.rgba(int, int, int, [double])
copied to clipboard

color format options: hex('#xxxxxx'), rgba(int, int, int, double) or [Color].

Background image
..background.image(
      {String url, 
      String path, 
      ColorFilter colorFilter, 
      ImageProvider<dynamic> imageProveder,
      BoxFit fit, 
      AlignmentGeometry alignment = Alignment.center, 
      ImageRepeat repeat = ImageRepeat.noRepeat})
copied to clipboard

Eighter the [url] or the [path] has to be specified. [url] is for network images and [path] is for local images.

Background blur
..background.blur(double blur)
copied to clipboard

Blurs the background. Can be used for example to achieve a "frosted glass" effect:

StyleClass()
  ..background.blur(10)
  ..background.rgba(255,255,255,0.15)
copied to clipboard

Does not work together with rotate().

Background blend mode
..background.blendMode(BlendMode blendMode)
copied to clipboard

Algorithms for blending background

Linear gradient
..linearGradient({AlignmentGeometry begin = Alignment.left,
      AlignmentGeometry end = Alignment.right,
      @required List<Color> colors,
      TileMode tileMode = TileMode.clamp,
      List<double> stops})
copied to clipboard
Radial gradient
..radialGradient(
    {AlignmentGeometry center = Alignment.center,
    @required double radius,
    @required List<Color> colors,
    TileMode tileMode = TileMode.clamp,
    List<double> stops})
copied to clipboard
Sweep gradient
..sweepGradient(
    {AlignmentGeometry center = Alignment.center,
    double startAngle = 0.0,
    @required double endAngle,
    @required List<Color> colors,
    TileMode tileMode = TileMode.clamp,
    List<double> stops})
copied to clipboard

In the style widget constructor, specify what angle calculation format you want to use.

Opacity
..opacity(double opacity)
copied to clipboard

Opacity applied on the whole widget.

Value must not be negative.

Border
..border(
      {double all,
      double left,
      double right,
      double top,
      double bottom,
      Color color = const Color(0xFF000000),
      BorderStyle style = BorderStyle.solid})
copied to clipboard

Choose between all, left, right, top and bottom. all works together with the other properties. color format options: hex('#xxxxxx'), rgb(int, int, int), rgba(int, int, int, double) or [Color].

Border radius
..borderRadius(
      {double all,
      double topLeft,
      double topRight,
      double bottomLeft,
      double bottomRight})
copied to clipboard

It is valid to use all together with single sided properties. Single sided properties will trump over the all property.

See also [circle] for creating circular widgets.

Circle
..circle([bool enable = true])
copied to clipboard

Makes the widget circular

Box shadow
..boxShadow(
      {Color color = const Color(0x33000000),
      double blur = 0.0,
      Offset offset = Offset.zero,
      double spread = 0.0})
copied to clipboard

See [elevation] for a different way of defining a box shadow.

Elevation
..elevation(
      double elevation,
      {double angle = 0.0,
      Color color = const Color(0x33000000),
      double opacity = 1.0})
copied to clipboard

Elevates the widget with a boxShadow. [opacity] is a relative constant

Scale
..scale(double ratio)
copied to clipboard

Scale the widget

Offset
..offset([double dx, double dy])
copied to clipboard

Offsets the widget

Rotate
..rotate(double angle)
copied to clipboard

Rotates the widget. By default one turn equals the value 1.0. To change to radians: StyleClass(useRadians: true).

Ripple
..ripple(bool enable, {dynamic splashColor, dynamic highlightColor})
copied to clipboard

Material ripple effect applied on tap.

Overflow
..overflow.visible({Axis direction = Axis.vertical})
..overflow.scrollable({Axis direction = Axis.vertical})
..overflow.hidden()
copied to clipboard

Change child overflow behaviour. Choose the overflow direction with the [direction] parameter.

Width, minWidth, maxWidth, Height, minHeight, maxHeight
..[type](double dimension)
copied to clipboard

Parent #

Parent(
  style: ParentStyle,
  gesture: Gestures,
  child: Widget
)
copied to clipboard

As the name suggests this widget is a simple styled widget which takes a child.

ParentStyle #

// format
ParentStyle()
  ..[style method]

// example
ParentStyle()
  ..width(100)
  ..padding(all: 10)
  ..elevation(5)
copied to clipboard
Add
..add(ParentStyle parentStyle, {bool override = false})
copied to clipboard

Combines style from two styled widgets.

Clone
..ParentStyle().clone()
copied to clipboard

This will clone the ParentStyle widget. This is usefull if you for example want to add more style to a widget without modifying the initial style.

Txt #

Txt(
  String,
  style: TxtStyle,
  gesture: Gestures,
)
copied to clipboard

As the name suggests this widget is a simple styled widget which takes a String as its child. This widget enables text styling with the TxtStyle widget. This also has the possibility to make the widget editable.

TxtStyle #

// format
TxtStyle()
  ..[style method]

// example
TxtStyle()
  ..width(100)
  ..padding(all: 10)
  ..textColor(Colors.blue)
  ..bold()
copied to clipboard
Editable
..editable(bool enable,
      {TextInputType keyboardType,
      String placeholder,
      bool obscureText = false,
      int maxLines,
      void Function(String) onChange,
      void Function(bool focus) onFocusChange,
      void Function(TextSelection, SelectionChangedCause) onSelectionChanged,
      void Function() onEditingComplete,
      FocusNode focusNode})
copied to clipboard

This makes the widget editable, just like a TextField, its just much easier to style

Text align
..textAlign.center()
copied to clipboard
Font weight
..fontWeight(FontWeight fontWeight)
copied to clipboard

A shorthand to make the text bold:

..bold([bool enable])
copied to clipboard
Italic
..italic([bool enable])
copied to clipboard
Font family
..fontFamily(String font, {List<String> fontFamilyFallback})
copied to clipboard
Text color
..textColor(Color textColor)
copied to clipboard
Max lines
..maxLines(int maxLines)
copied to clipboard
Letter spacing
..letterSpacing(double space)
copied to clipboard
Word spacing
..wordSpacing(double space)
copied to clipboard
Text decoration
..textDecoration(TextDecoration decoration)
copied to clipboard
Text shadow
..textShadow({Color color = const Color(0x33000000),
    double blur = 0.0,
    Offset offset = Offset.zero})
copied to clipboard
Text elevation
..textElevation(double elevation,
    {double angle = 0.0,
    Color color = const Color(0x33000000),
    double opacity = 1.0})
copied to clipboard
Add
..add(TxtStyle txtStyle, {bool override = false})
copied to clipboard

This adds together two TxtStyles. The override property specifies if already defined properties should be overrided.

Clone
..TxtStyle().clone()
copied to clipboard

This will clone the TxtStyle widget. This is usefull if you for example want to add more style to a widget without modifying the initial style.

Gestures #

isTap
..isTap((isTapped) => setState(() => pressed = isTapped))
copied to clipboard

Called whenever the tap state on the widget changes. This replaces the use of onTapDown, onTapUp and onTapCancel together.

Other
..onTap()
..onTapUp()
..onTapCancel()
..onDoubleTap()
..onTapDown()
..onLongPress()
..onLongPressStart()
..onLongPressEnd()
..onLongPressMoveUpdate()
..onLongPressUp()
..onVerticalDragStart()
..onVerticalDragEnd()
..onVerticalDragDown()
..onVerticalDragCancel()
..onVerticalDragUpdate()
..onHorizontalDragStart()
..onHorizontalDragEnd()
..onHorizontalDragCancel()
..onHorizontalDragUpdate()
..onHorizontalDragDown()
..onForcePressStart()
..onForcePressEnd()
..onForcePressPeak()
..onForcePressUpdate()
..onPanStart()
..onPanEnd()
..onPanCancel()
..onPanDown()
..onPanUpdate()
..onScaleStart()
..onScaleEnd()
..onScaleUpdate()
copied to clipboard

Examples and best practices #

Decoupling style from structure

final ParentStyle cardStyle = ParentStyle()
  ..height(175)
  ..padding(horizontal: 20.0, vertical: 10)
  ..alignment.center()
  ..background.hex('#3977FF')
  ..borderRadius(all: 20.0)
  ..elevation(10, color: hex('#3977FF'));

Widget build(BuildContext context) {
  return Parent(
    style: cardStyle,
    child: Widget,
  );
}
copied to clipboard

Variable dependent style

final Color color = Colors.blue;

final cardStyle = (color) => ParentStyle()
  ..height(175)
  ..padding(horizontal: 20.0, vertical: 10)
  ..alignment.center()
  ..background.color(color)
  ..borderRadius(all: 20.0)
  ..elevation(10, color: color);

Widget build(BuildContext context) {
  return Parent(
    style: cardStyle(color),
    child: Widget,
  );
}
copied to clipboard

Animated widgets

bool pressed = false;

final cardStyle = (pressed) => ParentStyle()
  ..height(175)
  ..padding(horizontal: 20.0, vertical: 10)
  ..alignment.center()
  ..borderRadius(all: 20.0)
  ..animate(200, Curves.easeOut)
  ..background.color(pressed ? Colors.white : Colors.black)
  ..elevation(pressed ? 10 : 20);

Widget build(BuildContext context) {
  return Parent(
    style: cardStyle(pressed),
    gesture: Gestures()
      ..isTap((isPressed) => setState(() => pressed = isPressed)),
    child: Widget,
  );
}
copied to clipboard

or

bool pressed = false;

final cardStyle = (pressed) => ParentStyle()
  ..height(175)
  ..padding(horizontal: 20.0, vertical: 10)
  ..alignment.center()
  ..borderRadius(all: 20.0)
  ..animate(200, Curves.easeOut)
  ..background.color(pressed ? Colors.white : Colors.black)
  ..elevation(pressed ? 10 : 20);

Gestures cardGesture() => Gestures()
  ..isTap((isPressed) => setState(() => pressed = isPressed));

Widget build(BuildContext context) {
  return Parent(
    style: cardStyle(pressed),
    gesture: cardGesture(),
    child: Widget,
  );
}
copied to clipboard
200
likes
80
points
168
downloads

Publisher

unverified uploader

Weekly Downloads

2024.09.09 - 2025.03.24

Simple to use yet powerfull style widgets with syntax inspired by CSS.

Repository (GitHub)

Documentation

API reference

License

MIT (license)

Dependencies

flutter

More

Packages that depend on division