katMessagePopup<T> function

Future<T?> katMessagePopup<T>({
  1. required BuildContext context,
  2. String? content,
  3. Widget? child,
  4. String? title,
  5. VoidCallback? onPressed,
  6. List<Widget>? actions,
})

Shows a modal message popup with a grey title bar and content.

Defaults to the localized "Notification!" title and a single "OK" action; tapping OK invokes onPressed when given, otherwise it just dismisses the popup. Pass title to override the title text, or actions to replace the default OK action entirely (in which case onPressed is ignored). Pass child instead of (or alongside) content to show arbitrary content - e.g. a list or an image - rather than plain text; child takes priority over content when both are given.

Implementation

Future<T?> katMessagePopup<T>({
  required BuildContext context,
  String? content,
  Widget? child,
  String? title,
  VoidCallback? onPressed,
  List<Widget>? actions,
}) {
  assert(
    content != null || child != null,
    'katMessagePopup requires either content or child',
  );

  final textTheme = Theme.of(context).textTheme;
  final hintColor = Theme.of(context).hintColor;
  final locales = KatLocales.of(context)!;

  return katBasePopup<T>(
    context: context,
    title: Text(
      key: const Key('popupMessage'),
      title ?? '${locales.lblNotification}!',
      style: textTheme.titleMedium!.copyWith(color: hintColor),
    ),
    backgroundColorTitle: KatColors.grey,
    content: SingleChildScrollView(
      child: child ?? Text(content!, style: textTheme.titleMedium),
    ),
    actions:
        actions ??
        <Widget>[
          KatButtonPopup(
            key: Key(KatKeys.btnOk),
            title: locales.lblOk,
            onPressed: onPressed ?? () => Navigator.of(context).pop(),
          ),
        ],
  );
}