findByMethodName method
Finds the first frame with the specified method name.
This method searches through the stack trace frames in hierarchical order (most recent first) and returns the first frame that matches the specified method name. This is useful for locating specific method invocations within a complex call stack.
Example Usage
void findSpecificMethod() {
final traceMapping = TraceMapping.fromStackTrace(StackTrace.current);
final validationFrame = traceMapping.findByMethodName('validateInput');
if (validationFrame != null) {
logger.info('Validation occurred at: ${validationFrame.packageUri}:${validationFrame.lineNumber}');
}
}
@param methodName The method name to search for in the stack trace @return The first matching frame, or an empty frame if no match found
Implementation
TraceFrame? findByMethodName(String methodName) {
return _frames.firstWhere(
(frame) => frame.getMethodName() == methodName,
orElse: () => TraceFrame.empty("")
);
}