VisualDensity class

Defines the visual density of user interface components.

Density, in the context of a UI, is the vertical and horizontal "compactness" of the components in the UI. It is unitless, since it means different things to different UI components.

The default for visual densities is zero for both vertical and horizontal densities, which corresponds to the default visual density of components in the Material Design specification. It does not affect text sizes, icon sizes, or padding values.

For example, for buttons, it affects the spacing around the child of the button. For lists, it affects the distance between baselines of entries in the list. For chips, it only affects the vertical size, not the horizontal size.

Here are some examples of widgets that respond to density changes:

See also:

Mixed in types
Annotations

Constructors

VisualDensity({double horizontal = 0.0, double vertical = 0.0})
A const constructor for VisualDensity.
const

Properties

baseSizeAdjustment Offset
The base adjustment in logical pixels of the visual density of UI components.
no setter
hashCode int
The hash code for this object.
no setteroverride
horizontal double
The horizontal visual density of UI components.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
vertical double
The vertical visual density of UI components.
final

Methods

copyWith({double? horizontal, double? vertical}) VisualDensity
Copy the current VisualDensity with the given values replacing the current values.
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
override
effectiveConstraints(BoxConstraints constraints) BoxConstraints
Return a copy of constraints whose minimum width and height have been updated with the baseSizeAdjustment.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringShort() String
A brief description of this object, usually just the runtimeType and the hashCode.
override

Operators

operator ==(Object other) bool
The equality operator.
override

Static Properties

adaptivePlatformDensity VisualDensity
Returns a VisualDensity that is adaptive based on the current platform on which the framework is executing, from defaultTargetPlatform.
no setter

Static Methods

defaultDensityForPlatform(TargetPlatform platform) VisualDensity
Returns a VisualDensity that is adaptive based on the given platform.
lerp(VisualDensity a, VisualDensity b, double t) VisualDensity
Linearly interpolate between two densities.

Constants

comfortable → const VisualDensity
The profile for a "comfortable" interpretation of VisualDensity.
compact → const VisualDensity
The profile for a "compact" interpretation of VisualDensity.
maximumDensity → const double
The maximum allowed density.
minimumDensity → const double
The minimum allowed density.
standard → const VisualDensity
The default profile for VisualDensity in ThemeData.