import 'package:flutter/material.dart'; /// A simple widget that displays an alert message in the center. class AlertMessage extends StatelessWidget { final String message; final Color? color; final bool centered; final EdgeInsetsGeometry? padding; final bool vertical; final IconData? trailingIcon; final VoidCallback? onTrailingIconPressed; const AlertMessage({ super.key, required this.message, this.centered = true, this.color, this.padding, this.vertical = false, this.trailingIcon, this.onTrailingIconPressed, }); @override Widget build(BuildContext context) { final colorScheme = Theme.of(context).colorScheme; final defaultColor = vertical ? colorScheme.onSurfaceVariant : colorScheme.onSurface; final Widget widget; if (vertical) { widget = Column( mainAxisAlignment: MainAxisAlignment.center, mainAxisSize: MainAxisSize.min, spacing: 8, children: [ Icon(Icons.info_outline_rounded, color: color ?? defaultColor), Text( message, textAlign: centered ? TextAlign.center : TextAlign.start, style: TextStyle(color: color ?? defaultColor), ), ], ); } else { widget = Row( mainAxisAlignment: centered ? MainAxisAlignment.center : MainAxisAlignment.start, spacing: 8, children: [ Icon(Icons.info_outline_rounded, color: color ?? defaultColor), Flexible( child: Text( message, style: TextStyle(color: color ?? defaultColor), ), ), if (trailingIcon != null) ...[ const SizedBox(width: 8), IconButton( icon: Icon(trailingIcon, color: color ?? defaultColor), onPressed: onTrailingIconPressed, padding: EdgeInsets.zero, constraints: const BoxConstraints(), iconSize: 20, ), ], ], ); } final effectivePadding = padding ?? (vertical ? const EdgeInsets.symmetric(horizontal: 24) : null); return effectivePadding != null ? Padding(padding: effectivePadding, child: widget) : widget; } }