build method

MaterialBanner build(
  1. BuildContext context, {
  2. VoidCallback? onClose,
  3. VoidCallback? onCancel,
})

Implementation

MaterialBanner build(BuildContext context, {VoidCallback? onClose, VoidCallback? onCancel}) {
  final foregroundColor = color.brightness.isDark ? Colors.white : Colors.black;
  final textTheme = Theme.of(context).textTheme;
  final actions =
      this.actions ??
      [if (onClose != null) MessageAction(label: MaterialLocalizations.of(context).closeButtonLabel, onTap: onClose)];
  return MaterialBanner(
    backgroundColor: color,
    leading: Icon(icon, color: foregroundColor),
    content: Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Text(title, style: textTheme.titleMedium!.copyWith(color: foregroundColor)),
        if (body != null) Text(body!, style: textTheme.bodySmall!.copyWith(color: foregroundColor.blend(color, .12))),
      ],
    ),
    onVisible: onCancel == null
        ? null
        : () => (cancel ?? Future.delayed(const Duration(seconds: 4))).whenComplete(onCancel),
    actions: actions
        .map(
          (action) => OutlinedButton(
            onPressed: action.onTap,
            child: Text(action.label, style: TextStyle(color: foregroundColor)),
          ),
        )
        .toList(),
  );
}