Box class
A Container equivalent widget for applying styles using Mix.
Box
is a concrete implementation of StyledWidget that applies custom styles
to a single child widget using the styling capabilities inherited from
StyledWidget. It wraps the child in a BoxSpecWidget
, which is responsible for
rendering the styled output.
The primary purpose of Box
is to provide a flexible and reusable way to style
widgets without the need to repeatedly define common style properties. It leverages
the Style object to define the appearance and allows inheriting styles from
ancestor StyledWidgets in the widget tree.
Inheriting Styles
If the inherit property is set to true
, Box
will merge its defined style with
the style from the nearest MixProvider ancestor in the widget tree. This is
useful for cascading styles down the widget tree.
Performance Considerations
While Box
provides a convenient way to style widgets, be mindful of the
performance implications of using complex styles and deep inheritance trees.
Overuse of style inheritance can lead to increased widget rebuilds and might
affect the performance of your application.
See also:
- Style, which defines the visual properties to be applied.
- BoxSpecWidget, which is used internally by
Box
to render the styled widget. - Container, which is the Flutter equivalent widget.
- Inheritance
Constructors
Properties
- child → Widget?
-
The child widget that will receive the styles.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- inherit → bool
-
Whether the widget should inherit its style from its parent.
finalinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
-
orderOfDecorators
→ List<
Type> -
finalinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- style → Style
-
The style to apply to the widget.
finalinherited
Methods
-
applyDecorators(
MixData mix, Widget child) → Widget -
inherited
-
build(
BuildContext context) → Widget -
Describes the part of the user interface represented by this widget.
override
-
createElement(
) → StatelessElement -
Creates a StatelessElement to manage this widget's location in the tree.
inherited
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
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
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
-
withMix(
BuildContext context, Widget builder(BuildContext context)) → Widget -
Applies a mix of inherited and local styles to the widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited