Ui Message
Model with @freezed for handling SnackBar and AlertDialog UI states (success, error, initial) and dynamic color based on state.Attributes:
Name | Type | Description | Default Value | Required | Nullable |
---|---|---|---|---|---|
message |
| SnackBar body text message. | - | ||
action |
| SnackBar action text. | - | ||
state |
| Handle (colors, icons) depending on UiMessage state |
|
Example:
/// handle uiMessage
void _handleUiMessage(UiMessage uiMessage) {
final message = uiMessage.message;
final action = uiMessage.action;
final color = uiMessage.color;
if (message != null) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text(message),
backgroundColor: color,
action: SnackBarAction(
label: action ?? 'Ok',
textColor: Colors.white,
onPressed: () {},
),
),
);
}
}