Hello, World!
To start, create a CustomBoxy widget and pass it a subclass of BoxyDelegate:

class MyWidget extends StatelessWidget {
const MyWidget({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return CustomBoxy(
delegate: MyBoxyDelegate(),
children: const [
Text('Hello, World!'),
],
);
}
}
class MyBoxyDelegate extends BoxyDelegate {}
CustomBoxy accepts a list of children, it's default behavior is similar to a Stack, passing through the constraints to each child and sizing itself to the biggest one.
There are many methods you can override in BoxyDelegate, the most common being layout.
Custom Layout
To customize layout, override the layout method to return a size:
class MyBoxyDelegate extends BoxyDelegate {
@override
// Choose the smallest size that our constraints allow, just like
// an empty SizedBox().
Size layout() => constraints.smallest;
}
BoxyDelegate includes several getters that are useful for layout, including:
- constraints, the BoxConstraints provided by the parent
- children, a list of BoxyChild instances which let you interact with things passed to CustomBoxy
- getChild, a method that can get a child by id using BoxyId
- hasChild, a method that returns true if there is a child with a given id
- layoutData, a variable you can use to hold additional data created during layout
- render, a raw reference to the RenderBoxy of CustomBoxy
- buildContext, the BuildContext of the CustomBoxy.