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() {
  String? visual, logical;
  if (_topLeft == _topRight &&
      _topRight == _bottomLeft &&
      _bottomLeft == _bottomRight) {
    if (_topLeft != Radius.zero) {
      if (_topLeft.x == _topLeft.y) {
        visual = 'BorderRadius.circular(${_topLeft.x.toStringAsFixed(1)})';
      } else {
        visual = 'BorderRadius.all($_topLeft)';
      }
    }
  } else {
    // visuals aren't the same and at least one isn't zero
    final StringBuffer result = StringBuffer();
    result.write('BorderRadius.only(');
    bool comma = false;
    if (_topLeft != Radius.zero) {
      result.write('topLeft: $_topLeft');
      comma = true;
    }
    if (_topRight != Radius.zero) {
      if (comma) {
        result.write(', ');
      }
      result.write('topRight: $_topRight');
      comma = true;
    }
    if (_bottomLeft != Radius.zero) {
      if (comma) {
        result.write(', ');
      }
      result.write('bottomLeft: $_bottomLeft');
      comma = true;
    }
    if (_bottomRight != Radius.zero) {
      if (comma) {
        result.write(', ');
      }
      result.write('bottomRight: $_bottomRight');
    }
    result.write(')');
    visual = result.toString();
  }
  if (_topStart == _topEnd &&
      _topEnd == _bottomEnd &&
      _bottomEnd == _bottomStart) {
    if (_topStart != Radius.zero) {
      if (_topStart.x == _topStart.y) {
        logical = 'BorderRadiusDirectional.circular(${_topStart.x.toStringAsFixed(1)})';
      } else {
        logical = 'BorderRadiusDirectional.all($_topStart)';
      }
    }
  } else {
    // logicals aren't the same and at least one isn't zero
    final StringBuffer result = StringBuffer();
    result.write('BorderRadiusDirectional.only(');
    bool comma = false;
    if (_topStart != Radius.zero) {
      result.write('topStart: $_topStart');
      comma = true;
    }
    if (_topEnd != Radius.zero) {
      if (comma) {
        result.write(', ');
      }
      result.write('topEnd: $_topEnd');
      comma = true;
    }
    if (_bottomStart != Radius.zero) {
      if (comma) {
        result.write(', ');
      }
      result.write('bottomStart: $_bottomStart');
      comma = true;
    }
    if (_bottomEnd != Radius.zero) {
      if (comma) {
        result.write(', ');
      }
      result.write('bottomEnd: $_bottomEnd');
    }
    result.write(')');
    logical = result.toString();
  }
  if (visual != null && logical != null) {
    return '$visual + $logical';
  }
  if (visual != null) {
    return visual;
  }
  if (logical != null) {
    return logical;
  }
  return 'BorderRadius.zero';
}