toString method

  1. @override
String toString({
  1. bool compact = false,
  2. bool withOperations = true,
  3. bool withExecutedOperations = true,
})
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(
    {bool compact = false,
    bool withOperations = true,
    bool withExecutedOperations = true}) {
  final duration = this.duration;
  final error = this.error;

  return [
    'Transaction[#$id]{\n',
    '  open: $isOpen\n',
    '  executing: $isExecuting\n',
    '  committed: ${isCommitted ? 'true' : (isCommitting ? 'committing...' : 'false')}\n',
    '  aborted: $isAborted\n',
    if (abortError != null) '  abortError: $abortError\n',
    if (error != null)
      '  error: ${error is DBException ? error.messageAndOperation : ''}\n',
    if (extraErrors != null)
      '  extraErrors:\n    -- ${extraErrors!.map((e) => e is DBException ? e.messageAndOperation : e).join('\n    -- ')}\n',
    '  cachedEntities: $cachedEntitiesLength\n',
    '  external: $_external\n',
    if (duration != null) '  duration: ${duration.inMilliseconds} ms\n',
    if (withOperations) ...[
      if (compact) '  operations: ${operations.length}\n',
      if (!compact) '  operations: [\n',
      if (!compact && _operations.isNotEmpty)
        '    ${_operations.join(',\n    ')}',
      if (!compact) '\n  ],\n',
    ],
    if (withExecutedOperations) ...[
      if (compact) '  executedOperations: ${executedOperations.length}\n',
      if (!compact) '  executedOperations: [\n',
      if (!compact && _executedOperations.isNotEmpty)
        '    ${_executedOperations.join(',\n    ')}',
      if (!compact) '\n  ]\n',
    ],
    if (_commitCalled) '  result: $_result\n',
    '}'
  ].join();
}