Skip to content

Instantly share code, notes, and snippets.

@zty5678
Last active June 8, 2023 17:28
Show Gist options
  • Save zty5678/3ad0ff99f7ce74a4de558b495d4f6ecb to your computer and use it in GitHub Desktop.
Save zty5678/3ad0ff99f7ce74a4de558b495d4f6ecb to your computer and use it in GitHub Desktop.
flutter LOGD 打印行号
import 'package:flutter/foundation.dart';
void LOGD(Object message, StackTrace trace) {
try {
if (kDebugMode) {
CustomTrace programInfo = CustomTrace(trace);
// print("[(${programInfo.fileName}:${programInfo.lineNumber})]$message");
print("[(${programInfo.methodFullInfo})]$message");
}
} catch (e) {
print(e);
}
}
class CustomTrace {
final StackTrace _trace;
String methodFullInfo = "";
CustomTrace(this._trace) {
_parseTrace();
}
void _parseTrace() {
var list = this._trace.toString().split("\n");
var traceString = list.first;
// print("traceString=///$traceString///");
var begin = traceString.lastIndexOf("(") + 1;
var end = traceString.lastIndexOf(")");
methodFullInfo = traceString.substring(begin, end);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment