Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

advanced multi-child layouts

advanced multi-child layouts

this library provides several widgets and utilities that enable you to create advanced layouts without in-depth knowledge of the framework and minimal boilerplate.

flex layouts

advanced multi-child layouts

a common pattern is when you need one or more widgets in a row or column to have the same cross axis size
as another child in the list, you can achieve this layout using boxyrow and dominant, for example:

advanced multi-child layouts

boxyrow(
  mainaxissize: mainaxissize.min,
  children: [
    child1(),
    dominant(child: column(
      mainaxissize: mainaxissize.min,
      children: [
        child2(),
        child3(),
      ],
    )),
  ],
]);

complex custom layouts

advanced multi-child layouts

for more complex layouts this library provides customboxy, a multi-child layout widget that allows you to inflate,
constrain, lay out, and paint each child manually similar to a custommultichildlayout.

this is useful if you need layouts that no other widget can provide, for example one where one child is positioned above
the border of two others:

68747470733a2f2f692e7473742e73682f31675638592e706e67

class mylayout extends statelesswidget {
  final widget top;
  final widget middle;
  final widget bottom;
  
  // the margin between the middle widget and right edge
  final double inset;
  
  mylayout({
    @required this.top,
    @required this.middle,
    @required this.bottom,
    @required this.inset,
  });

  @override
  widget build(context) => customboxy(
    delegate: mydelegate(inset: inset),
    children: [
      // use layoutid to give each child an id
      layoutid(id: #top, child: top),
      layoutid(id: #bottom, child: bottom),
      // the middle widget should be rendered above the others
      // so we put it at the bottom of the list
      layoutid(id: #middle, child: middle),
    ],
  );
}

class mydelegate extends boxydelegate {
  final double inset;

  mydelegate({@required this.inset});
  
  @override
  size layout() {
    // get each child handle by a symbol id
    var top = getchild(#top);
    var middle = getchild(#middle);
    var bottom = getchild(#bottom);
    
    // children should have unbounded height
    var topconstraints = constraints.widthconstraints();
    
    // lay out and position top widget
    var topsize = title.layout(topconstraints);
    top.position(offset.zero);
    
    // lay out and position middle widget using size of top widget
    var middlesize = middle.layout(boxconstraints());
    middle.position(offset(
      topsize.width - (middle.width + inset),
      topsize.height - middle.height / 2,
    ));
    
    // lay out bottom widget
    var bottomsize = info.layout(topconstraints.tighten(
      // bottom widget should be same width as top widget
      width: topsize.width,
    ));
    
    // position bottom widget directly below top widget
    bottom.position(offset(0, topsize.height));
    
    // calculate total size
    return size(
      topsize.width,
      topsize.height + bottomsize.height,
    );
  }
  
  // check if any properties have changed
  @override
  bool shouldrelayout(mydelegate old) => old.inset != inset;
}

see the product tile example for an implementation of this
layout, and the documentation of customboxy for
more information.

sliver containers

advanced multi-child layouts

ever want to give sliverlist a box decoration? the sliver library
provides slivercontainer which allows you to use a box widget as the foreground or background of a sliver:

68747470733a2f2f692e7473742e73682f756137324c2e676966

this card effect can be achieved with slivercard:

slivercard(
  color: colors.white,
  clipbehavior: clip.antialias,
  sliver: sliverlist(...),
)

the following example uses slivercontainer to give sliverlist a rounded blue border:

slivercontainer(
  // how far the background will extend off-screen, prevents the border
  // from shrinking as the sliver is scrolled out of view
  bufferextent: 12.0,
  
  // the background and foreground are layed out to cover the visible
  // space of the sliver
  background: decoratedbox(
    border: border.all(
      color: colors.blue,
      width: 2,
    ),
    borderradius: borderradius.circular(12),
  ),

  margin: edgeinsets.all(8.0),
  padding: edgeinsets.all(8.0),
  sliver: sliverlist(...),
)

utilities

the utils library provides extensions with axis dependant
methods and constructors for several data types. these extensions make writing direction agnostic math significantly
easier.

full list of methods:

boxconstraintsaxisutil.create
boxconstraintsaxisutil.expand
boxconstraintsaxisutil.tightfor
boxconstraintsaxisutil.tightforfinite
boxconstraints.hastightaxis
boxconstraints.hastightcrossaxis
boxconstraints.hasboundedaxis
boxconstraints.hasboundedcrossaxis
boxconstraints.hasinfiniteaxis
boxconstraints.hasinfinitecrossaxis
boxconstraints.maxaxis
boxconstraints.minaxis
boxconstraints.maxcrossaxis
boxconstraints.mincrossaxis
boxconstraints.tightenaxis
boxconstraints.constrainaxisdimensions
boxconstraints.constrainaxis
boxconstraints.constraincrossaxis
boxconstraints.copywithaxis
boxconstraints.axisconstraints
boxconstraints.crossaxisconstraints
axis.cross
axis.direction
axis.crossdirection
verticaldirection.reversed
verticaldirection.direction
axisdirection.axis
axisdirection.crossaxis
axisdirection.isreverse
axisdirection.isforward
axisdirection.reversed
axisdirection.ccw
axisdirection.cw
axisdirection.operator+
axisdirection.operator-
renderbox.getminintrinsicaxis
renderbox.getminintrinsiccrossaxis
renderbox.getmaxintrinsicaxis
renderbox.getmaxintrinsiccrossaxis
offsetaxisutil.create
offsetaxisutil.direction
offset.axisoffset
offset.crossaxisoffset
offset.directionextent
sizeaxisutil.create
sizeaxisutil.from
sizeaxisutil.crossfrom
size.axissize
size.crossaxissize
edgeinsetsaxisutil.create
edgeinsetsaxisutil.symmetric
edgeinsetsaxisutil.direction
edgeinsets.directionextent
axissizedbox

Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

Top