debugPrintStack function

void debugPrintStack ({String label, int maxFrames })

Dump the current stack to the console using debugPrint and FlutterError.defaultStackFilter.

The current stack is obtained using StackTrace.current.

The maxFrames argument can be given to limit the stack to the given number of lines. By default, all non-filtered stack lines are shown.

The label argument, if present, will be printed before the stack.


void debugPrintStack({ String label, int maxFrames }) {
  if (label != null)
  Iterable<String> lines = StackTrace.current.toString().trimRight().split('\n');
  if (kIsWeb) {
    // Remove extra call to StackTrace.current for web platform.
    // TODO(ferhat): remove when
    // is addressed.
    lines = lines.skip(1);
  if (maxFrames != null)
    lines = lines.take(maxFrames);