Flutter:获取Android Studio中print()语句的行号 [英] Flutter: Get line number for print() statements, Android Studio

查看:81
本文介绍了Flutter:获取Android Studio中print()语句的行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 android studio(flutter插件)上使用 flutter ,无论如何我都能得到 print 语句或 debugPrint 语句?

I am using flutter on android studio(flutter plugin) and is there anyway i can get the line number of print statement or debugPrint statements?

当前它打印为:

flutter: sarmad@
flutter: sarm
flutter: null

它应同时适用于 IOS android .

推荐答案

我认为您需要此来进行调试.

I assume you need this for debugging purposes.

您可以手动在打印语句中输入行号(输入类和/或方法的名称对我来说更好).

You can put the line number manually in the print statement(putting the class and/or method's name is better for me).

您可以使用:

print(StackTrace.current);

或这个(几乎相同):

debugPrintStack();

打印堆栈跟踪,其中包括调用print和行号的类和方法,其余堆栈跟踪则使输出混乱.因此,您可以使用 debugPrintStack(label:'sarmad',maxFrames:2); 仅打印当前堆栈跟踪的前两行.

to print the stack trace which includes the class and method that called the print and the line number, and the rest of the stack trace which makes the output messy. So you can use debugPrintStack(label: 'sarmad',maxFrames: 2); to print just the first 2 lines of the current stack trace.

这篇关于Flutter:获取Android Studio中print()语句的行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆