📜  获取当前行号 dart flutter - Dart 代码示例

📅  最后修改于: 2022-03-11 14:48:09.086000             🧑  作者: Mango

代码示例1
int get lineNumber {
    try {
      final re =
          RegExp(r'^#1[ \t]+.+:(?[0-9]+):[0-9]+\)$', multiLine: true);
      final match = re.firstMatch(StackTrace.current.toString());
      return (match == null) ? -1 : int.parse(match.namedGroup('line'));
    } catch (e) {
      return 0;
    }
  }
  
  // Usage
  print('Current line No :$lineNumber');