debugLog function

void debugLog(
  1. String message, {
  2. String? debugLabel,
  3. dynamic value,
  4. bool silent = false,
})

Function that prints a debug message to the console if the app is running in debug mode.

This function takes a message as the main content of the debug log. It also accepts an optional debugLabel, which can be used to provide a label for the log message. If a value is provided, it will be appended to the message, separated by " => ".

Example:

debugLog('Hello, world!', debugLabel: 'Greeting', value: 42);
// Output: "[Greeting]: Hello, world! => 42"

Implementation

void debugLog(
  String message, {
  String? debugLabel,
  dynamic value,
  bool silent = false,
}) {
  // Check if the app is running in debug mode
  if (kDebugMode && !silent) {
    // Append the debug label to the message if provided
    if (debugLabel != null) {
      message = '[$debugLabel]: $message';
    }

    // Append the value to the message if provided
    if (value != null) {
      message = '$message => $value';
    }

    // Print the final message to the console
    debugPrint(message);
  }
}