Class Log {log._ (); static voidprintMsg(Object obj) {
    assert(() {
      print(obj.toString());
      return true;
    }());
  }
}

Copy the code

There’s a lot of this in system code, because assertions are only executed in debug mode, so you can put some code in an assertion that only needs to be executed in debug mode, but is not executed at release, such as the one we see in the beginner phase:

RenderFlex, for example, has code like this in its paint method:

@override
  void paint(PaintingContext context, Offset offset) {
    if(_overflow <= 0.0) {defaultPaint(context, offset);return;
    }

    // There's no point in drawing the children if we're empty.
    if (size.isEmpty)
      return;

    // We have overflow. Clip it.
    context.pushClipRect(needsCompositing, offset, Offset.zero & size, defaultPaint);

    assert(() {
      // Only set this if it's null to save work. It gets reset to null if the // _direction changes. final String debugOverflowHints = 'The overflowing $runtimeType has an orientation of $_direction.\n' 'The edge of the $runtimeType that is overflowing has been marked ' 'in the rendering with a yellow and black striped pattern. This is ' 'usually caused by the contents being too big for the $runtimeType. ' 'Consider applying a flex factor (e.g. using an Expanded widget) to ' 'force the children of the $runtimeType to fit within the available ' 'space instead of being sized to their natural size.\n' 'This is considered an error condition because it indicates that there ' 'is content that cannot be seen. If the content is legitimately bigger ' 'than the available space, consider clipping it with a ClipRect widget ' 'before putting it in the flex, or using a scrollable container rather ' 'than a Flex, like a ListView.'; // Simulate a child rect that overflows by the right amount. This child // rect is never used for drawing, just for determining the overflow // location and amount. Rect overflowChildRect; Switch (_direction) {case Axis. Horizontal: overflowChildRect = rect. fromLTWH(0.0, 0.0, sie.width + _overflow, 0.0); break; Case Axis. Vertical: overflowChildRect = rect. fromLTWH(0.0, 0.0, 0.0, size. Height + _overflow); break; } paintOverflowIndicator(context, offset, Offset.zero & size, overflowChildRect, overflowHints: debugOverflowHints); return true; } ()); }Copy the code