|
| 1 | +# ThemedAlert — API Reference |
| 2 | + |
| 3 | +Source: `lib/src/alerts/` |
| 4 | + |
| 5 | +- `ThemedAlert` class — `src/alert.dart` line 37 |
| 6 | +- `ThemedAlertType` enum — `src/type.dart` |
| 7 | +- `ThemedAlertStyle` enum — `src/style.dart` |
| 8 | +- `ThemedAlertIcon` class — `src/icon.dart` line 24 |
| 9 | + |
| 10 | +--- |
| 11 | + |
| 12 | +## Examples |
| 13 | + |
| 14 | +```dart |
| 15 | +// Default — info type, layrz style |
| 16 | +ThemedAlert( |
| 17 | + title: 'Heads up', |
| 18 | + description: 'This action cannot be undone after 30 days.', |
| 19 | +) |
| 20 | +
|
| 21 | +// Warning with filledTonal background |
| 22 | +ThemedAlert( |
| 23 | + type: .warning, |
| 24 | + style: .filledTonal, |
| 25 | + title: 'Low disk space', |
| 26 | + description: 'You have less than 500 MB remaining.', |
| 27 | +) |
| 28 | +
|
| 29 | +// Danger with filled (solid) background |
| 30 | +ThemedAlert( |
| 31 | + type: .danger, |
| 32 | + style: .filled, |
| 33 | + title: 'Account suspended', |
| 34 | + description: 'Your account has been suspended due to policy violations.', |
| 35 | +) |
| 36 | +
|
| 37 | +// Success outlined (inside a Card) |
| 38 | +ThemedAlert( |
| 39 | + type: .success, |
| 40 | + style: .outlined, |
| 41 | + title: 'Export complete', |
| 42 | + description: 'Your file has been exported and is ready to download.', |
| 43 | +) |
| 44 | +
|
| 45 | +// FilledIcon style — two-column layout |
| 46 | +ThemedAlert( |
| 47 | + type: .info, |
| 48 | + style: .filledIcon, |
| 49 | + title: 'New version available', |
| 50 | + description: 'Version 3.2 introduces improved performance and bug fixes.', |
| 51 | +) |
| 52 | +
|
| 53 | +// Custom type — override icon and color |
| 54 | +ThemedAlert( |
| 55 | + type: .custom, |
| 56 | + color: const Color(0xFF6A0DAD), |
| 57 | + icon: LayrzIcons.solarOutlineShieldCheck, |
| 58 | + title: 'Identity verified', |
| 59 | + description: 'Your identity has been verified successfully.', |
| 60 | +) |
| 61 | +
|
| 62 | +// Extended description with bumped maxLines |
| 63 | +ThemedAlert( |
| 64 | + type: .context, |
| 65 | + title: 'About this feature', |
| 66 | + description: 'This feature is in beta. Some behaviors may change without ' |
| 67 | + 'notice. Please report any issues to the support team.', |
| 68 | + maxLines: 5, |
| 69 | +) |
| 70 | +``` |
| 71 | + |
| 72 | +--- |
| 73 | + |
| 74 | +## Constructor |
| 75 | + |
| 76 | +```dart |
| 77 | +const ThemedAlert({ |
| 78 | + super.key, |
| 79 | + this.type = .info, |
| 80 | + required this.title, |
| 81 | + required this.description, |
| 82 | + this.maxLines = 3, |
| 83 | + this.style = .layrz, |
| 84 | + this.color, |
| 85 | + this.icon, |
| 86 | + this.iconSize, |
| 87 | +}); |
| 88 | +``` |
| 89 | + |
| 90 | +--- |
| 91 | + |
| 92 | +## Properties |
| 93 | + |
| 94 | +| Property | Type | Default | Notes | |
| 95 | +|---|---|---|---| |
| 96 | +| `type` | `ThemedAlertType` | `.info` | Semantic severity. Drives the default icon and color. See enum table below. | |
| 97 | +| `title` | `String` | — | **Required.** Bold heading text of the alert. | |
| 98 | +| `description` | `String` | — | **Required.** Body text. Clipped at `maxLines` with an ellipsis. | |
| 99 | +| `maxLines` | `int` | `3` | Maximum lines for `description`. Increase when the message is known to be longer. | |
| 100 | +| `style` | `ThemedAlertStyle` | `.layrz` | Visual surface treatment. See enum table below. | |
| 101 | +| `color` | `Color?` | `null` | Used **only** when `type == .custom`. Has no effect for other types. | |
| 102 | +| `icon` | `IconData?` | `null` | Used **only** when `type == .custom`. Has no effect for other types. | |
| 103 | +| `iconSize` | `double?` | `null` | Icon size. Defaults to `25` when `style == .filledIcon`, `22` otherwise. | |
| 104 | + |
| 105 | +--- |
| 106 | + |
| 107 | +## `ThemedAlertType` enum |
| 108 | + |
| 109 | +| Value | Default icon | Default color | Notes | |
| 110 | +|---|---|---|---| |
| 111 | +| `.info` | `solarOutlineInfoSquare` | `Colors.blue` | Neutral informational hint. Default type. | |
| 112 | +| `.success` | `solarOutlineCheckSquare` | `Colors.green` | Confirmation that an action completed. | |
| 113 | +| `.warning` | `solarOutlineDangerSquare` | `Colors.orange` | Reversible caution; user can still proceed. | |
| 114 | +| `.danger` | `solarOutlineCloseSquare` | `Colors.red` | Blocking or destructive condition. | |
| 115 | +| `.context` | `solarOutlineMenuDotsSquare` | `Colors.grey` | Muted, low-emphasis metadata note. | |
| 116 | +| `.custom` | `null` (must set `icon`) | `null` (must set `color`) | Both `icon` and `color` are **required** when using this type. | |
| 117 | + |
| 118 | +--- |
| 119 | + |
| 120 | +## `ThemedAlertStyle` enum |
| 121 | + |
| 122 | +| Value | Description | |
| 123 | +|---|---| |
| 124 | +| `.layrz` | Soft tonal icon chip + plain text on a transparent background. Default. | |
| 125 | +| `.filledTonal` | Background filled at ~20% alpha of the type color; text and icon in type color. | |
| 126 | +| `.filled` | Solid type-color background. Text color is auto-contrasted via `validateColor(typeColor)`. | |
| 127 | +| `.outlined` | Transparent background with a 1 px type-color border. | |
| 128 | +| `.filledIcon` | Two-column layout: icon column filled with type color; body column uses `scaffoldBackgroundColor`. | |
| 129 | + |
| 130 | +--- |
| 131 | + |
| 132 | +## Companion — `ThemedAlertIcon` |
| 133 | + |
| 134 | +Standalone colored icon badge matching the alert's type palette. Use when you need just the badge without a title or description — for example, as a status indicator in a table row. |
| 135 | + |
| 136 | +```dart |
| 137 | +const ThemedAlertIcon({ |
| 138 | + super.key, |
| 139 | + this.type = .info, |
| 140 | + this.size = 30, |
| 141 | + this.iconSize = 20, |
| 142 | + this.padding = const EdgeInsets.all(5), |
| 143 | + this.color, |
| 144 | + this.icon, |
| 145 | +}); |
| 146 | +``` |
| 147 | + |
| 148 | +| Property | Type | Default | Notes | |
| 149 | +|---|---|---|---| |
| 150 | +| `type` | `ThemedAlertType` | `.info` | Drives the icon and background color. | |
| 151 | +| `size` | `double` | `30` | Diameter of the circular badge. | |
| 152 | +| `iconSize` | `double` | `20` | Icon size inside the badge. | |
| 153 | +| `padding` | `EdgeInsetsGeometry` | `EdgeInsets.all(5)` | Internal padding around the icon. | |
| 154 | +| `color` | `Color?` | `null` | Used only when `type == .custom`. | |
| 155 | +| `icon` | `IconData?` | `null` | Used only when `type == .custom`. | |
| 156 | + |
| 157 | +--- |
| 158 | + |
| 159 | +## Behavior notes |
| 160 | + |
| 161 | +- **`.filledIcon` layout:** renders a `Row` with two columns — the left column is a `Container` filled with the type color and the right column uses the scaffold's background color. The icon column width is determined by `iconSize + padding`. |
| 162 | +- **`.filled` text contrast:** body text color is computed via `validateColor(typeColor)`, which selects black or white for maximum legibility — do not manually set text color inside a `.filled` alert. |
| 163 | +- **`.filledTonal` alpha:** background is `typeColor.withAlpha(51)` (≈ 20% opacity on any surface). |
| 164 | +- **`.outlined` border:** 1 px `BoxDecoration` border using the type color; no background fill. |
| 165 | +- **No dialog helper:** `ThemedAlert` is intentionally a pure layout widget with no `show()` or imperative API. Wrap it in `showDialog`, `ScaffoldMessenger.showSnackBar`, or any other mechanism the caller controls. |
0 commit comments