用途
该技能用于在 shadcn_ui(Flutter)应用中显示 Toast——简洁的临时消息,常用于展示操作结果或反馈。典型用途包括:表单提交成功提示、请求失败提醒、需要用户立即响应的错误消息等。
主要能力
- 显示提示:通过
ShadToaster.of(context).show(ShadToast(...))弹出 Toast。 - 关闭提示:调用
toaster.hide()手动关闭,例如在操作按钮中调用。 - 可选内容:
ShadToast支持可选的title、description和action。 - 错误样式:使用
ShadToast.destructive显示错误风格的 Toast,并可搭配ShadButton.destructive与ShadDecoration定制操作按钮的边框样式。 - 前置条件:组件树中需要预先放置一个 toaster(例如
ShadToaster)。
使用方式
基础用法(仅描述):
ShadToaster.of(context).show(
const ShadToast(
description: Text('Your message has been sent.'),
),
);
带标题:
ShadToaster.of(context).show(
const ShadToast(
title: Text('Uh oh! Something went wrong'),
description: Text('There was a problem with your request'),
),
);
带操作按钮(点击后关闭提示):
ShadToaster.of(context).show(
ShadToast(
title: const Text('Uh oh! Something went wrong'),
description: const Text('There was a problem with your request'),
action: ShadButton.outline(
child: const Text('Try again'),
onPressed: () => ShadToaster.of(context).hide(),
),
),
);
错误样式(destructive):
final theme = ShadTheme.of(context);
ShadToaster.of(context).show(
ShadToast.destructive(
title: const Text('Uh oh! Something went wrong'),
description: const Text('There was a problem with your request'),
action: ShadButton.destructive(
child: const Text('Try again'),
decoration: ShadDecoration(
border: ShadBorder.all(
color: theme.colorScheme.destructiveForeground,
width: 1,
),
),
onPressed: () => ShadToaster.of(context).hide(),
),
),
);
适用场景
适用于需要在 shadcn_ui 组件生态中向用户展示短暂、非阻塞式消息的场景,例如提交反馈、错误提醒或带“重试”操作的通知。
限制
资料未提供关于平台兼容性、版本要求、收费或性能限制的信息;具体可用的参数与行为以官方文档为准,此处暂未提供。