Is there a way to trace the output of Flutter debugPrint() i.e. is there a way we can look at the console output and know which line of a dart file is the source of the debugPrint() output ?
I am using android studio.
CodePudding user response:
you can use debugPrint, for e.g.,
import 'package:flutter/foundation.dart';
debugPrint('movieTitle: $movieTitle');
Or, use Dart's built in log() function
import 'dart:developer';
log('data: $data');
CodePudding user response:
After digging around for a few more hours I came across debugPrintStack(), however this wasn't prefect as it resulted in a minimum of 3 lines being taken up in the console evetime you want to print to the console.
I created the below method for debug printing to the console including the print source all on one line in the console i.e. it is now possible to look at the console and know exactly where each and every debug print originated from.
//declare method
static debugPri(String s, StackTrace stackTrace){
String printOriginStr = (stackTrace.toString().split(')'))[0];
debugPrint(s ' --debugPri source: ' printOriginStr);
}
//call method to output message to console
debugPri('this is a test message', StackTrace.current);