shadcn_ui-toast
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseShadcn UI — Toast
Shadcn UI — Toast
Instructions
使用说明
Toasts are succinct temporary messages. Ensure a toaster is in the tree (e.g. ). Get it with . Call to show a toast; use to dismiss (e.g. from an action button). Use with optional , , and . Use for error-style toasts with a destructive action button (use to style the action border).
ShadToasterShadToaster.of(context)toaster.show(ShadToast(...))toaster.hide()ShadToasttitledescriptionactionShadToast.destructiveShadDecoration提示消息(Toast)是简洁的临时消息。确保组件树中已存在提示器(例如)。通过获取实例。调用来显示提示消息;调用来关闭(例如通过操作按钮触发)。使用时可选择设置、和参数。若要显示带破坏性操作按钮的错误风格提示消息,可使用(可通过设置操作按钮的边框样式)。
ShadToasterShadToaster.of(context)toaster.show(ShadToast(...))toaster.hide()ShadToasttitledescriptionactionShadToast.destructiveShadDecorationSimple
基础示例
dart
ShadToaster.of(context).show(
const ShadToast(
description: Text('Your message has been sent.'),
),
);dart
ShadToaster.of(context).show(
const ShadToast(
description: Text('Your message has been sent.'),
),
);With title
带标题的示例
dart
ShadToaster.of(context).show(
const ShadToast(
title: Text('Uh oh! Something went wrong'),
description: Text('There was a problem with your request'),
),
);dart
ShadToaster.of(context).show(
const ShadToast(
title: Text('Uh oh! Something went wrong'),
description: Text('There was a problem with your request'),
),
);With action
带操作按钮的示例
dart
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(),
),
),
);dart
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
破坏性样式示例
dart
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(),
),
),
);dart
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(),
),
),
);