build method
MaterialBanner
build(
- BuildContext context, {
- required ValueSetter<
MaterialBannerClosedReason> hide,
Implementation
MaterialBanner build(BuildContext context, {required ValueSetter<MaterialBannerClosedReason> hide}) {
final foregroundColor = color.brightness.isDark ? Colors.white : Colors.black;
final textTheme = Theme.of(context).textTheme;
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: () => (cancel ?? Future.delayed(const Duration(seconds: 4)))
.whenComplete(() => hide(MaterialBannerClosedReason.hide)),
actions: actions
.map((action) => action._build(
context, TextStyle(color: foregroundColor), () => hide(MaterialBannerClosedReason.dismiss)))
.toList());
}