Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR DART

get current line number dart flutter

int get lineNumber {
    try {
      final re =
          RegExp(r'^#1[ 	]+.+:(?<line>[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');
 
PREVIOUS NEXT
Tagged: #current #line #number #dart #flutter
ADD COMMENT
Topic
Name
9+3 =