Diagnostics
snippet.packages.flutter.lib.src.foundation.diagnostics.15.
// ignore_for_file: directives_ordering
// ignore_for_file: unnecessary_import
// ignore_for_file: unused_import
// ignore_for_file: unused_element
// ignore_for_file: unused_local_variable
import 'dart:async';
import 'dart:convert';
import 'dart:math' as math;
import 'dart:typed_data';
import 'dart:ui' as ui;
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/painting.dart';
import 'package:flutter/physics.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/semantics.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter/animation.dart';
import 'package:flutter/services.dart';
// From: packages/flutter/lib/src/foundation/diagnostics.dart:15
late int rows, columns;
late String _name;
late bool inherit;
MessageProperty table = MessageProperty('table size', '$columns\u00D7$rows');
MessageProperty usefulness = MessageProperty('usefulness ratio', 'no metrics collected yet (never painted)');
StringProperty name = StringProperty('name', _name);
dynamic expression9 =
FlagProperty(
'visible',
value: true,
ifFalse: 'hidden',
)
;
dynamic expression10 =
FlagProperty(
'inherit',
value: inherit,
ifTrue: '',
ifFalse: '',
)
;
enum Day {
monday, tuesday, wednesday, thursday, friday, saturday, sunday
}
void validateDescribeEnum() {
assert(Day.monday.toString() == 'Day.monday');
assert(describeEnum(Day.monday) == 'monday');
assert(Day.monday.name == 'monday'); // preferred for real enums
}
class ExampleSuperclass with Diagnosticable { late String message; late double stepWidth; late double scale; late double paintExtent; late double hitTestExtent; late double paintExtend; late double maxWidth; late bool primary; late double progress; late int maxLines; late Duration duration; late int depth; Iterable? boxShadow; late DiagnosticsTreeStyle style; late bool hasSize; late Matrix4 transform; Map? handles; late Color color; late bool obscureText; late ImageRepeat repeat; late Size size; late Widget widget; late bool isCurrent; late bool keepAlive; late TextAlign textAlign; }
class ExampleObject extends ExampleSuperclass {
// ...various members and properties...
@override
void debugFillProperties(DiagnosticPropertiesBuilder properties) {
// Always add properties from the base class first.
super.debugFillProperties(properties);
// Omit the property name 'message' when displaying this String property
// as it would just add visual noise.
properties.add(StringProperty('message', message, showName: false));
properties.add(DoubleProperty('stepWidth', stepWidth));
// A scale of 1.0 does nothing so should be hidden.
properties.add(DoubleProperty('scale', scale, defaultValue: 1.0));
// If the hitTestExtent matches the paintExtent, it is just set to its
// default value so is not relevant.
properties.add(DoubleProperty('hitTestExtent', hitTestExtent, defaultValue: paintExtent));
// maxWidth of double.infinity indicates the width is unconstrained and
// so maxWidth has no impact.,
properties.add(DoubleProperty('maxWidth', maxWidth, defaultValue: double.infinity));
// Progress is a value between 0 and 1 or null. Showing it as a
// percentage makes the meaning clear enough that the name can be
// hidden.
properties.add(PercentProperty(
'progress',
progress,
showName: false,
ifNull: '',
));
// Most text fields have maxLines set to 1.
properties.add(IntProperty('maxLines', maxLines, defaultValue: 1));
// Specify the unit as otherwise it would be unclear that time is in
// milliseconds.
properties.add(IntProperty('duration', duration.inMilliseconds, unit: 'ms'));
// Tooltip is used instead of unit for this case as a unit should be a
// terse description appropriate to display directly after a number
// without a space.
properties.add(DoubleProperty(
'device pixel ratio',
ui.window.devicePixelRatio,
tooltip: 'physical pixels per logical pixel',
));
// Displaying the depth value would be distracting. Instead only display
// if the depth value is missing.
properties.add(ObjectFlagProperty('depth', depth, ifNull: 'no depth'));
// bool flag that is only shown when the value is true.
properties.add(FlagProperty('using primary controller', value: primary));
properties.add(FlagProperty(
'isCurrent',
value: isCurrent,
ifTrue: 'active',
ifFalse: 'inactive',
showName: false,
));
properties.add(DiagnosticsProperty('keepAlive', keepAlive));
// FlagProperty could have also been used in this case.
// This option results in the text "obscureText: true" instead
// of "obscureText" which is a bit more verbose but a bit clearer.
properties.add(DiagnosticsProperty('obscureText', obscureText, defaultValue: false));
properties.add(EnumProperty('textAlign', textAlign, defaultValue: null));
properties.add(EnumProperty('repeat', repeat, defaultValue: ImageRepeat.noRepeat));
// Warn users when the widget is missing but do not show the value.
properties.add(ObjectFlagProperty('widget', widget, ifNull: 'no widget'));
properties.add(IterableProperty(
'boxShadow',
boxShadow,
defaultValue: null,
style: style,
));
// Getting the value of size throws an exception unless hasSize is true.
properties.add(DiagnosticsProperty.lazy(
'size',
() => size,
description: '${ hasSize ? size : "MISSING" }',
));
// If the `toString` method for the property value does not provide a
// good terse description, write a DiagnosticsProperty subclass as in
// the case of TransformProperty which displays a nice debugging view
// of a Matrix4 that represents a transform.
properties.add(TransformProperty('transform', transform));
// If the value class has a good `toString` method, use
// DiagnosticsProperty. Specifying the value type ensures
// that debugging tools always know the type of the field and so can
// provide the right UI affordances. For example, in this case even
// if color is null, a debugging tool still knows the value is a Color
// and can display relevant color related UI.
properties.add(DiagnosticsProperty('color', color));
// Use a custom description to generate a more terse summary than the
// `toString` method on the map class.
properties.add(DiagnosticsProperty
SHARE: