boxSize property

BoxSize boxSize

boxSize

box size on constrains work based on its maxWidth

Example:

  class Example extends StatelessWidget {
  const Example({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(
      builder: (_, constrains) {
        return Text("${constrains.boxSize}");
      },
    );
  }
}

Implementation

BoxSize get boxSize {
  final double width = maxWidth;

  /// if current maxWidth less than LayoutBreakPoint.kXsBreakPoint
  if (width < LayoutBreakPoint.kXsBreakPoint) {
    return BoxSize.xs;

    /// if current maxWidth between LayoutBreakPoint.kXsBreakPoint and LayoutBreakPoint.kSmBreakPoint
  } else if (LayoutBreakPoint.kXsBreakPoint <= width &&
      width < LayoutBreakPoint.kSmBreakPoint) {
    return BoxSize.sm;

    /// if current maxWidth between LayoutBreakPoint.kSmBreakPoint and LayoutBreakPoint.kMdBreakPoint
  } else if (LayoutBreakPoint.kSmBreakPoint <= width &&
      width < LayoutBreakPoint.kMdBreakPoint) {
    return BoxSize.md;

    /// if current maxWidth between LayoutBreakPoint.kMdBreakPoint and LayoutBreakPoint.kLgBreakPoint
  } else if (LayoutBreakPoint.kMdBreakPoint <= width &&
      width < LayoutBreakPoint.kLgBreakPoint) {
    return BoxSize.lg;

    /// else the size must be extremly large
  } else {
    return BoxSize.xl;
  }
}