Ask the assistant
0/400
Your question is processed by an AI service and kept to improve answers. Do not enter personal data.

    DecoratedBox

    Decorates its child with a BoxDecoration — color, gradient, border, rounded corners, shadow, background image.

    Type: single-child

    DecoratedBox
      #decoration color:#36345E
        #borderRadius circular 20
      Center
        Text "Content"

    Parameters

    Parameter Type Default Description
    position string background Decoration position: background , foreground

    Nested structures

    #decoration

    #decoration color:#36345E
      #borderRadius circular 16
      #border fromBorderSide
        #side color:#FF0000 width:2
      #gradient linear begin:centerLeft end:centerRight
        #colors #FF0000 #0000FF
      #boxShadow
        :# color:0x40000000 blurRadius:10
          #offset x:0 y:4
      #image "data/images/bg.jpg" fit:cover
    Parameter Type Description
    color color Background color
    shape string Shape: rectangle , circle
    backgroundBlendMode string Blend mode

    Nested inside #decoration :

    • #borderRadius — corner rounding: circular 16 , only topLeft:16 topRight:16
    • #border — border: fromBorderSide → #side , all → color: width: , directional → #top #bottom #start #end
    • #gradient — gradient: linear begin:... end:... → #colors , #stops
    • #boxShadow — shadows: :# positional items with color , blurRadius , spreadRadius and a nested #offset x: y: (or offset:zero )
    • #image — background image. The path and all background properties live on #image itself, on one level: src / url , #headers , scale , fit , alignment , opacity , repeat , colorFilter , centerSlice .
      #image "data/images/bg.jpg" fit:cover alignment:topCenter
    
      #image "https://example.com/bg.jpg" fit:cover scale:2
        #headers Authorization:"Bearer …"

    There is NO nested #image inside #image — that is a markup error the analyzer reports.

    Examples

    Card with rounded corners and a border

    DecoratedBox
      #decoration color:#36345E
        #borderRadius circular 20
        #border fromBorderSide
          #side color:#585593 width:2
      Padding
        #padding all 24
        Column spacing:8
          Text "Heading"
          Text "Description"

    Gradient background

    DecoratedBox
      #decoration
        #gradient linear begin:topCenter end:bottomCenter
          #colors #6C63FF #36345E
      Padding
        #padding all 40
        Center
          Text "Gradient"
            #style fontSize:24 color:#FFFFFF

    Radial gradient: circle and ellipse

    #gradient radial draws a circle : radius is a fraction of the box's SHORT side (this is how RadialGradient reads it), so in a wide box you get a spot in the middle, not a glow across the whole width.

    An ellipse is set by its axes — each a fraction of its own side, like the percentages in radial-gradient(ellipse X% Y%) :

    DecoratedBox
      #decoration
        #gradient radial radiusX:0.5 radiusY:0.18
          #colors 0x806938EF 0x006938EF
    Parameter Meaning
    radius Circle radius — a fraction of the short side ( 0.5 by default).
    radiusX Horizontal radius — a fraction of the width . Makes the gradient an ellipse.
    radiusY Vertical radius — a fraction of the height .

    If one axis is given, the other takes radius . If neither is given — a circle. An older version of the app that does not know radiusX and radiusY draws a circle — narrower than intended, but in the right place.

    Focus border (in a scroll's selectorBuilder)

    @Macros id:selectorBuilder isFocused:false
      DecoratedBox
        #decoration
          #borderRadius circular 20
          #border fromBorderSide
            #side color:{isFocused ? $focusColor : 0x00} width:3

    See also

    • ColoredBox — a plain background color without decoration
    • ClipRRect — clips the content to a rounded rectangle