mix
an expressive way to effortlessly build design systems in flutter. mix offers primitive building blocks to help developers and designers create beautiful and consistent ui.
important
mix is currently being used internally to build design systems in flutter.
however, it is still in the experimental development stages.
major apis are expected to change until the 1.0 release.
motivation & goals
- creating consistent custom (non-material) ui in flutter is difficult
- maintaining a design system is much harder than building it.
- visual attributes should be defined outside of a widget by a composable api shared across the design system.
- style consistently with a global theme
- respond to changing requirements quickly
- create adaptive layouts with ease
- material theme compatible
principles
- development efficiency is gained by the ease of use, consistency, and reusability, not coding speed.
- abstract flutter api, and not modify its behavior.
- composability should be a priority. mixes, attributes, widgets, etc.
- designer friendly (use simple standard semantics when possible)
examples
simple mix
final squaremix = mix(h(150), w(150));
box(
squaremix,
child: text('square'),
);
// you can also use the following:
// this way has some downsides. more info soon...
squaremix.box(child:text('square'));
composability
extend mixes
final cardmix = squaremix.mix(p(20), rounded(20), bgcolor(colors.white));
override mixes
final redcardmix = cardmix.mix(bgcolor(colors.red));
combine mixes
final elevationmix = mix(
shadowcolor(colors.black12),
shadowblur(4),
shadowoffset(0, 2),
);
box(
mix.combine(cardmix, elevationmix),
child: text('card with shadow'),
);
conditional mixes
// if you wan't to change the mix depending on a condition
final conditonalmix = mix.chooser(isselected, dynamicmix, redcardmix);
dynamic mixes
if you want the card to change color when in dark mode you can use a dynamic attribute.
final dynamicmix = cardmix.mix(dark(bgcolor(colors.black)));
/// now, when the app is on dark mode the card color will change to `black`.
box(
dynamicmix,
child: text('dynamic card'),
);
you can also leverage media query context values
final flexmix = mix(gap(20), mainaxis.center);
// adaptive gutter for your flex widgets using media query
final adaptiveflexmix = flexmix.mix(
mq.xs(gap(10)),
mq.sm(gap(15)),
mq.lg(gap(40)),
);
apis
documentation is currently in progress. for now you can find some of the available utilities here
concepts
here are some high-level concepts to understand how mix works and to allow for you to get started.
attributes
these are the features or characteristics of certain widgets. most attributes map out to layout, visual widgets, or widget styling itself. attributes are primitives which get translated into their flutter api.
dynamic attributes
attributes can be dynamic, which means they only are applied in case a condition is met. this allows for the creation of atributes that can be used depending on the widget’s buildcontext
.
utilities
these are classes whose primary purpose is providing a better api for attributes.
not required for building mixes; however, make a cleaner api possible and overall better development experience.
mixes
combination or mix
of attributes. mixes are passed to widgets and translated into the widget’s properties.
mixes can be reused across multiple widgets and also combine, extended, and overridden.
mixer widgets
these are the building block for your design system. you can easily build new widgets that take advantage of mixes; however, there are some primitives provided.
box
similar to a container
with some slight adjustments for a better development experience.
flexbox
the equivalent of the flex widgets (flex, row, column). allow for the use of flex attributes, and wrap them in a box
to use box attributes for composability.
columnbox
the equivalent of the column
widget. allows you to use mix attributes to style and build custom text widgets. it is an abstraction of flexbox
, so it will also accept box
attributes.
rowbox
the equivalent of the row
widget. allows you to use mix attributes to style and build custom text widgets. it is an abstraction of flexbox
, so it will also accept box
attributes.
textmix
the equivalent of the text widget. allows you to use mix attributes to style and build custom text widgets.
iconmix
the equivlent to the icon widget. allows to use mix attributes to style and build custom icon widgets.
Comments are closed.