Line data Source code
1 : import 'package:flutter/widgets.dart';
2 : import 'package:fossui/src/components/alert/foss_alert.dart';
3 : import 'package:fossui/src/components/toast/foss_toaster.dart';
4 :
5 : part 'foss_toast_style.dart';
6 :
7 : /// The kind of a [FossToast]: drives the leading glyph, its tint, and whether
8 : /// the toast auto-dismisses.
9 : enum FossToastVariant {
10 : /// A plain notification with no status glyph.
11 : neutral,
12 :
13 : /// A pending operation: shows a spinner and persists until updated.
14 : loading,
15 :
16 : /// Informational.
17 : info,
18 :
19 : /// A successful outcome.
20 : success,
21 :
22 : /// A caution.
23 : warning,
24 :
25 : /// An error or failure.
26 : error,
27 : }
28 :
29 : /// {@category Overlays}
30 : /// {@template foss.toast.preview}
31 : /// <img src="https://fossui.org/components/toast/overview/light.png"
32 : /// alt="FossToast, light theme" width="480"
33 : /// style="max-width:100%;height:auto" />
34 : /// <img src="https://fossui.org/components/toast/overview/dark.png"
35 : /// alt="FossToast, dark theme" width="480"
36 : /// style="max-width:100%;height:auto" />
37 : ///
38 : /// See the [toast documentation ↗](https://fossui.org/docs/components/toast) or
39 : /// try it live in the
40 : /// [playground ↗](https://play.fossui.org/components/#/?path=components/toast/fosstoaster/playground).
41 : /// {@endtemplate}
42 : ///
43 : /// One transient notification. Enqueue it with `showFossToast` or a
44 : /// `FossToastController`; the surface stays on the `popover` role for every
45 : /// [variant], which tints only the leading glyph.
46 : ///
47 : /// {@macro foss.customize}
48 : ///
49 : /// See also [FossToaster], the host that displays toasts, and [FossAlert] for a
50 : /// persistent inline message.
51 : ///
52 : /// ```dart
53 : /// showFossToast(
54 : /// context,
55 : /// const FossToast(variant: FossToastVariant.success, title: Text('Saved')),
56 : /// );
57 : /// ```
58 : @immutable
59 : class FossToast {
60 : /// {@macro foss.toast.preview}
61 : ///
62 : /// Creates a toast message.
63 1 : const FossToast({
64 : this.title,
65 : this.description,
66 : this.variant = FossToastVariant.neutral,
67 : this.icon,
68 : this.action,
69 : this.duration,
70 : this.style,
71 : });
72 :
73 : /// The title line.
74 : final Widget? title;
75 :
76 : /// The description below the title.
77 : final Widget? description;
78 :
79 : /// The kind of toast. Defaults to [FossToastVariant.neutral].
80 : final FossToastVariant variant;
81 :
82 : /// Overrides the default leading glyph (or the loading spinner). Null hides
83 : /// the leading slot for [FossToastVariant.neutral].
84 : final Widget? icon;
85 :
86 : /// An optional trailing action.
87 : final Widget? action;
88 :
89 : /// Overrides the auto-dismiss delay. Ignored for [FossToastVariant.loading],
90 : /// which persists.
91 : final Duration? duration;
92 :
93 : /// Per-instance visual overrides.
94 : final FossToastStyle? style;
95 : }
|