Skip to content

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: