toString method

  1. @override
String toString()
override

A string representation of this object.

Some classes have a default textual representation, often paired with a static parse function (like int.parse). These classes will provide the textual representation as their string representation.

Other classes have no meaningful textual representation that a program will care about. Such classes will typically override toString to provide useful information when inspecting the object, mainly for debugging or logging.

Implementation

@override
String toString() {
  var optionList = args.where((e) => !e.isFlag && !e.hide).toList();
  var flagList = args.where((e) => e.isFlag && !e.hide).toList();

  var text = '''
$title
$_intent命令: $name
''';

  if (description != null && description!.isNotEmpty) {
    text += '$_intent說明:\n';
    text += '$_intent$_intent$description\n\n';
  }

  if (optionList.isNotEmpty) {
    text += '$_intent參數:';
    for (var e in optionList) {
      text += '\n${e.toString()}';
    }
    text += '\n';
  }

  if (flagList.isNotEmpty) {
    text += '${_intent}Flag:';
    for (var e in flagList) {
      text += '\n${e.toString()}';
    }
    text += '\n';
  }

  if (example != null) {
    text += '\n$_intent範例:\n$example';
  }

  return text;
}