Container
A decorated box that can hold a child widget with background color, border, rounded corners, and shadow.
Basic Usage
Container(
Text("Hello"),
Background(Blue),
)
Options
| Option | Type | Description | Example |
|---|---|---|---|
Background |
color.NRGBA |
Sets the background color | Background(color.NRGBA{R: 255, G: 0, B: 0, A: 255}) |
BorderRadius |
float32 |
Sets the corner radius in dp | BorderRadius(12) |
Border |
BorderStyle |
Sets the border style | Border(BorderAll(2, Blue)) |
Shadow |
float32 |
Sets the elevation/shadow depth | Shadow(8) |
Helper Functions
| Function | Description | Example |
|---|---|---|
BorderAll(width, color) |
Creates a uniform border on all sides | BorderAll(2, Gray500) |
Examples
// Container with background color
Container(
Text("Colored background"),
Background(color.NRGBA{R: 200, G: 230, B: 255, A: 255}),
)
// Container with rounded corners
Container(
Text("Rounded"),
Background(Blue),
BorderRadius(16),
)
// Container with border
Container(
Text("Bordered"),
Border(BorderAll(2, Gray500)),
BorderRadius(8),
)
// Container with shadow
Container(
Text("Elevated"),
Background(White),
BorderRadius(12),
Shadow(8),
)
// Container with all options
Container(
Text("Full styling"),
Background(color.NRGBA{R: 240, G: 255, B: 240, A: 255}),
BorderRadius(20),
Border(BorderAll(3, Green)),
Shadow(12),
)
// Nested containers
Container(
Container(
Text("Inner"),
Background(Yellow),
BorderRadius(8),
),
Background(Purple),
BorderRadius(12),
)
Predefined Colors
The theme provides common colors for convenience:
White, Black, Transparent
Gray50, Gray100, Gray200, Gray300, Gray400, Gray500, Gray600, Gray700, Gray800, Gray900
Red, Pink, Purple, Indigo, Blue, Cyan, Teal, Green, Yellow, Orange