DiagnosticsProperty<T>.lazy constructor

DiagnosticsProperty<T>.lazy(
  1. String? name,
  2. ComputePropertyValueCallback<T> computeValue, {
  3. String? description,
  4. String? ifNull,
  5. String? ifEmpty,
  6. bool showName = true,
  7. bool showSeparator = true,
  8. Object? defaultValue = kNoDefaultValue,
  9. String? tooltip,
  10. bool missingIfNull = false,
  11. bool expandableValue = false,
  12. bool allowWrap = true,
  13. bool allowNameWrap = true,
  14. DiagnosticsTreeStyle style = DiagnosticsTreeStyle.singleLine,
  15. DiagnosticLevel level = DiagnosticLevel.info,
})

Property with a value that is computed only when needed.

Use if computing the property value may throw an exception or is expensive.

The level argument is just a suggestion and can be overridden if something else about the property causes it to have a lower or higher level. For example, if calling computeValue throws an exception, level will always return DiagnosticLevel.error.

Implementation

DiagnosticsProperty.lazy(
  String? name,
  ComputePropertyValueCallback<T> computeValue, {
  String? description,
  String? ifNull,
  this.ifEmpty,
  super.showName,
  super.showSeparator,
  this.defaultValue = kNoDefaultValue,
  this.tooltip,
  this.missingIfNull = false,
  this.expandableValue = false,
  this.allowWrap = true,
  this.allowNameWrap = true,
  DiagnosticsTreeStyle super.style = DiagnosticsTreeStyle.singleLine,
  DiagnosticLevel level = DiagnosticLevel.info,
}) : assert(defaultValue == kNoDefaultValue || defaultValue is T?),
     _description = description,
     _valueComputed = false,
     _value = null,
     _computeValue = computeValue,
     _defaultLevel = level,
     ifNull = ifNull ?? (missingIfNull ? 'MISSING' : null),
     super(
       name: name,
     );