Solving Size Issues with Print Statements in Flutter

Solving Size Issues with Print Statements in Flutter

Printing your way out of a sizing issue is not the common way to go. But, it’s fast and efficient. Most of the time. So let me tell you how I use a simple extension method to give me feedback and information with just a single line of code.

"Like a torch in the dark, print statements illuminate the path of errors. Embrace their guidance, for through understanding our faults, we attain wisdom." ~ Debuctetus

Size Reporter

Let’s start with the sizing widget. This widget was made and introduced to me by my Flutter mentor @kavantix back in the day. The SizeReporter holds your widget as a child after which it passes the sizing information through a debouncer into a callback.

💡 Disclaimer: using this widget to constrain or resize your child widget is inefficient because it will trigger an unwanted rebuild. However, it’s ideal for debugging purposes.

class SizeReporter extends SingleChildRenderObjectWidget {
  const SizeReporter({Key? key, required Widget child, required this.onSizeChanged})
      : super(key: key, child: child);
  final void Function(Size size) onSizeChanged;

  _SizeReporterRenderObject createRenderObject(BuildContext context) =>

  void updateRenderObject(BuildContext context, covariant _SizeReporterRenderObject renderObject) {
    renderObject.onSizeChanged = onSizeChanged;

class _SizeReporterRenderObject extends RenderProxyBox {
  void Function(Size size) onSizeChanged;

  Size? _oldSize;

  final _debouncer = Debouncer();

  void performLayout() {
    if (size != _oldSize) { {
        _oldSize = size;

💡 If you don’t have a Debouncer in your project use this one:

class Debouncer {
    Duration duration = const Duration(milliseconds: 300),
  }) : _duration = duration;

  final Duration _duration;
  Timer? _timer;

  void run(VoidCallback voidCallback) {
    _timer = Timer(
      () {

  void tryCancel() => _timer?.cancel();

Widget Extension

Now comes the fun part. Using a widget extension, we can easily wrap this builder around any widget to give you the right size information.

But that's not all. It also has a coloured container around it so we can easily see how much space the widget takes up in the UI. This is ideal for situations where we are not quite sure how the UI is structured.

You can also combine these to provide yourself with even more information without ever opening the Flutter Inspector.

The extension is down below, edit it to your liking. My print statements tend to be a bit too much for most people 😄.

extension WidgetExtension on Widget {
  Widget get withRedDebug => withDebug(color:, label: 'Red');
  Widget get withGreenDebug => withDebug(color:, label: 'Green');
  Widget get withBlueDebug => withDebug(color:, label: 'Blue');
  Widget get withYellowDebug => withDebug(color: Colors.yellow, label: 'Yellow');
  Widget get withPurpleDebug => withDebug(color: Colors.purple, label: 'Purple');
  Widget get withOrangeDebug => withDebug(color:, label: 'Orange');
  Widget get withPinkDebug => withDebug(color:, label: 'Pink');
  Widget get withCyanDebug => withDebug(color: Colors.cyan, label: 'Cyan');
  Widget get withTealDebug => withDebug(color: Colors.teal, label: 'Teal');

  Widget withDebug({Color? color, String? label}) => Container(
        color: (color ??,
        child: SizeReporter(
          child: this,
          onSizeChanged: (size) {
            if (kDebugMode) {
                '''[🐛] [PRINT] [🌟] [with${label}Debug] [📞] [height]: ${size.height} [width]: ${size.width}''',

Happy debugging! The screenshots used are from my personal app called Float Note. Float Note is a task management app built for people with ADHD, busy professionals and other busy bees a like. You can download it here. Give it a try! I’m sure you’ll like it 😁 And if you want, use code “HASHNODE50“ for 50% off your subscription when the time comes. Thank you for reading this far, until next time 🙏.

👋 About me: I am an independent developer with ADHD and the creator of Float Note. Float Note is an ADHD power tool that gives busy minds the ability live a stress free life. Features include an AI scheduling tool, priority poker and unique mechanism to quickly capture and organize the many thoughts and ideas we have on a daily base.

🎫 It would mean the world to me if you gave it a try and let me know what you think through one of my socials. You can try it for free for 7 days and when the time comes, use code "DEVLIFEOFBRIAN" to get over 70% off your lifetime subscription.

📲 Download it here or click the link in my bio (Android/iOS/web) ➡️

Thank you for reading this far 🫡 stay focused! 🤙

#flutterdev #buildinpublic #adhdtool #productivity #indiedev

Did you find this article valuable?

Support Dev Life of Brian by becoming a sponsor. Any amount is appreciated!