printRich function

void printRich(
  1. Object? object, {
  2. bool printToConsole = kDebugMode,
  3. Color? foreground,
  4. Color? background,
  5. bool italic = false,
  6. bool bold = false,
  7. bool underline = false,
  8. bool slowBlink = false,
  9. bool rapidBlink = false,
  10. bool invert = false,
  11. bool conceal = false,
  12. bool strike = false,
  13. bool gothic = false,
  14. bool doubleUnderline = false,
  15. bool framed = false,
  16. bool encircled = false,
  17. bool overlined = false,
  18. bool timestamp = false,
  19. DateTime? startTime,
  20. DateFormat? timeFormatter,
  21. Color? underlineColor,
  22. RichStyle? style,
})

Print object with settable styles and colors. Note that some parameters and features might not be supported by your IDE. For more info regarding supportability please look at RichStyle or visit ANSI escape code documentation

  • Timestamp If a startTime is provided the timestamp will be the duration from the start time to now. If no startTime the current date time with the timeFormatter will be displayed as timestamp.

Implementation

void printRich(
  Object? object, {
  bool printToConsole = kDebugMode,
  Color? foreground,
  Color? background,
  bool italic = false,
  bool bold = false,
  bool underline = false,
  bool slowBlink = false,
  bool rapidBlink = false,
  bool invert = false,
  bool conceal = false,
  bool strike = false,
  bool gothic = false,
  bool doubleUnderline = false,
  bool framed = false,
  bool encircled = false,
  bool overlined = false,
  bool timestamp = false,
  DateTime? startTime,
  DateFormat? timeFormatter,
  Color? underlineColor,
  RichStyle? style,
}) {
  // * Time stamp
  String stringTime = "";
  final time = DateTime.now();
  if (timestamp) {
    if (startTime == null) {
      final formatter = timeFormatter ?? DateFormat('hh:mm:ss');
      stringTime = "${formatter.format(time)} | ";
    } else {
      stringTime = "${time.difference(startTime)} | ";
    }
  }

  // * print style
  final printStyle = (style ?? RichStyle()).copyWith(
    foreground: foreground,
    background: background,
    italic: italic,
    bold: bold,
    underline: underline,
    slowBlink: slowBlink,
    rapidBlink: rapidBlink,
    invert: invert,
    conceal: conceal,
    strike: strike,
    gothic: gothic,
    doubleUnderline: doubleUnderline,
    framed: framed,
    encircled: encircled,
    overlined: overlined,
    underlineColor: underlineColor,
  );

  if (printToConsole) {
    print(stringTime + printStyle.applyTo(object.toString()));
  }
}