just_sonner 0.8.0
just_sonner: ^0.8.0 copied to clipboard
Stacking toasts for Flutter desktop in the spirit of sonner: a deck that fans out on hover, toasts updated in place, promise toasts, no BuildContext.
0.8.0 #
- The deck can be warmed up so the first open after launch does not drop a frame (#168).
toast.warmUp()fans out a deck of its own once, with one stand-in toast built from the controller's config — yourbuilderor the default card, and thedeckBackdropwhen there is one — under the app's screen, and takes it away, so the first real open is not also the first time it is drawn. It works withSonnerHost; attached withattach, it does nothing. Call it while the app's screen is opaque. The stand-in is not one of your toasts and nothing you read from the controller changes. Nothing runs unless you call it.
0.7.0 #
- An app can set how long each of the deck's motions takes (#162).
SonnerConfig(motionDurations: MotionDurations(...))takes oneDurationfor each of six motions:enter(400 ms),exit(200 ms),expand(400 ms),glide(400 ms),springBack(400 ms) andhide(300 ms). The defaults are the timings the deck already had, so nothing changes on upgrade. Each duration also times what moves with that motion:entermoves the toasts behind and fades the empty card,exitcovers a swipe out and the gap closing, andexpandfades the toasts beyond the window and eases the scroll back to the edge. Zero puts a motion at its end in one frame; a negative duration fails an assert. A motion already running keeps the duration it started with. Curves are unchanged. - The dismiss-all control can show with one toast (#163).
DeckDismissAll(minCount: 1)shows it, its look or yourbuilder, as soon as one toast the user may dismiss is up, so the deck's far end keeps the same shape as the hide control, which already shows with one.minCountis the fewest toasts that show it. It defaults to 2, as before, and must be at least- Loading toasts and
dismissible: falseones still do not count.
- Loading toasts and
- A header reads one toast as "1 notification" (#163). With no
countLabel, the dismiss-all and hide headers used to read "1 notifications" for a single toast. AcountLabelyou give is unchanged.
0.6.0 #
- The README's mode-1 example attaches after
runApp. It calledtoast.attachbeforerunApp, which throws "Binding has not yet been initialized" in debug, sinceattachreads the navigator key; the spec already said afterrunApp. - Attaching another navigator moves the toasts on screen at once (#152).
attachwith a different key, orattachafterdetach, took the toasts out of the old overlay and drew nothing in the new one until the nextshow, andraise()could not bring them back. With a toast alive or the zone open,attachnow puts them into the new navigator's overlay right away, at the end of the frame when called during a build. With nothing to draw, or no navigator built under the key, it inserts nothing, as before. - A request finishing after its screen closed no longer reports an error (#155). A
promisewhose future settled after the controller was disposed reported aFlutterErrorin debug, which failed a widget test that closed a screen mid-request, and in release added a toast to the disposed controller. Its success or error state is now dropped: no toast, no report, and the future's own result or error still reaches the caller. dismissanddismissAllon a disposed controller assert before they change anything (#155). They removed the toast first and then threw, and an id not on screen passed silently. They now assert at once, asshowandupdatedo. In release they still act.- A builder's content can change in place on a see-through card (#157). On an update or a
replace the new content fades in over the old, which stayed opaque underneath, so a builder
whose card is see-through showed the old content through the whole fade and lost it in one
frame.
SonnerConfig.contentChangetakes aContentChange:cardOpacityset to the card's own opacity fades the old out so the two layers read as one card, 0 being a plain cross-fade;durationsets the fade's length, zero swapping in one frame;keep: truekeeps the builder's widget, and its state, across every update and replace with no fade, so the card animates what changes itself. The defaults are the fade as before, and the default look keeps its own fade.ContentChangeis exported. - The content an update or a replace fades out no longer takes the focus (#157). A button in it could be reached with Tab for the length of the fade.
toast.isAlive(id)says whether a given toast is still up (#150). It is true fromshowuntil the toast is dismissed or runs out, and stays true across a replace. An app adding to a toast it shows at its own id can now tell whether that toast has gone, by any way it can leave, and start afresh. It has no side effect. It does not say when a toast left or why, and there is still no callback for that.toast.holdTimers()lets an app pause the timers (#149). It returns aTimerHold, and the timers stay paused untilrelease()is called on it. On Windows and Linux a window covered by another reportsinactive, which does not pause, so toasts ran out while the user was in another window. An app can now take a hold onAppLifecycleListener.onInactiveand release it ononResume, or on any other signal it has. Each call is a hold of its own, and releasing one twice does nothing.TimerHoldis exported. By defaultinactivestill does not pause.toast.raise()puts attached toasts back on top (#148). An entry another package inserted into the root overlay after the toasts covered them until the next toast, andzone.open()on an open zone did not lift them.raise()moves them back over it, keeping their state and animations. It does nothing before a toast is shown or the zone opened, afterdetach, and withSonnerHost.- Toasts can come in from the side (#141).
SonnerConfig.enterMotiontakes aToastEnterMotion:edge, the slide from the top or bottom edge as before and the default, orleftorright, which bring every toast in one toast's width from that side and take it out the same way. The side does not followposition. A toast already leaving when you assign another motion keeps leaving the way it was going, and a swiped toast still leaves the way it was swiped.ToastEnterMotionis exported. - Breaking: the deck can hide to the side (#141).
DeckHideMotionLookgainsslideLeftandslideRight, which carry the deck past that side of the window, fading, and bring it back the same way.DeckHideMotion()still slides past the edge. An exhaustiveswitchoverDeckHideMotionLookin your code needs the two new cases. - A banner on a zone hidden empty slides in from the right distance (#143). A zone hidden
before its deck was laid out or while it was empty, or a host built on a hidden zone, brought
the next toast's banner in from the wrong distance under every slide: from across the window,
or from just past its edge. The way back is now measured from the deck as it comes back, so a
deck hidden open, which folds up as it goes, also comes back from its folded size. A motion
builder's
reachis unchanged. - The backdrop's blur fades in rather than growing (#142). With
deckBackdropset, opening the zone or fanning the deck out drew the blur at a sigma that grew from 0 toblur, and the first opens after launch dropped frames while the engine met each new sigma. The blur is now drawn atblurthroughout, so an open no longer walks through every sigma, and fades in and out by its opacity; the dim is unchanged.DeckBackdropis unchanged.
0.5.1 #
toast.countsays how many toasts are alive (#122), those beyondvisibleToastsand those that are not dismissible included. The controller's listeners are its change signal. An app can light a dot on its own button while a hidden zone has toasts, and bring the zone back once it is empty. With a banner up, the zone reads as hidden with toasts in the count.- A toast that leaves a hidden deck is gone at once (#123). It kept a 200 ms exit nobody could
see, and if
reveal(),open()or a new toast's banner brought the deck back during it, the toast showed again for about 100 ms after it had gone. A toast leaving a deck that is still on screen, a banner included, exits as before. A builder'sToastView.animationdoes not run down for a toast with no exit, andToastView.dismiss's future completes as it is removed. - A deck brought back while it hides comes back (#124). With the pointer holding the deck, a
listener that called
zone.reveal(),zone.open()or showed a toast in the notificationzone.hide()sends left the deck out of sight and out of reach, with the zone reading as shown or open, or a banner up. The deck now ends where the zone's state says. - A toast leaving beyond
visibleToastsis gone at once (#126). It kept a 200 ms exit nobody could see, and ifzone.open()or the pointer fanned the deck out during it, the toast showed for up to about 180 ms after it had gone. A toast crossing the edge of the window as it leaves, or leaving a deck that is fanned out, exits as before. As for a hidden deck,ToastView.animationdoes not run down for a toast with no exit, andToastView.dismiss's future completes as it is removed. - A press does not hold a hidden deck (#128). A press that hid the deck from a listener, or
that a host carried to a hidden controller, left
zone.heldtrue on a deck nothing drew, and a swipe from it dismissed a toast out of sight. It is now let go of, as hiding lets go of any other press, and no swipe starts from it. A banner takes a press and a swipe as before. - The dismiss-all control reads each toast as it reaches it (#129). A listener that made a toast not dismissible during it, or dismissed one and showed another at its id, lost that toast too. Now it stays. A toast replaced at its id during the press still goes if it is dismissible.
- Hiding the deck cancels a click under way (#132). A press on a toast's close button or
action that the deck hid under completed on release, dismissing a toast out of sight or running
the action. The pointer is now cancelled as the deck hides. The cancel reaches everything that
pointer was routed through, a tap detector wrapped around
SonnerHostincluded, and hover on the app's widgets catches up at the next mouse move after the release. - A deck on its way back takes the pointer only where it is drawn (#133). For the 300 ms after
zone.reveal(), or while a banner comes up, a click at the deck's resting place was held by the deck with nothing drawn there and never reached the app. It now reaches the app unless the deck is drawn under it. - A toast entering takes the pointer only where it is drawn (#137). For the 400 ms of its enter, a click at the place it was headed went to the deck with nothing drawn there. It now reaches the app until the toast has arrived, unless the pointer already holds the deck.
0.5.0 #
- The deck glides under the mouse wheel (#107). A notch turned over a deck whose toasts do not fit moved it about 60 px in one frame; it now glides there on a spring that settles in 400 ms, and notches turned during a glide add to it. A toast arriving or leaving under a glide keeps the toasts you are reading in place. The same goes for a wheel over the dismiss-all and hide controls. A trackpad pan and a drag of the scrollbar's thumb move the deck as before.
- Set how the deck glides (#110).
SonnerConfig.wheelMotiontakes aWheelMotion:WheelMotion.spring()by default, or another spring, a curve, a lerp, orWheelMotion.spring(duration: Duration.zero)to jump as in 0.4.2. A motion assigned while toasts are on screen applies from the next wheel turn. Two configs with equal motions are equal, even when the motions are built from runtime values (#118), so a config rebuilt every build with the same motion does not read as a change. WheelMotionis exported frompackage:just_sonner/just_sonner.dart, so you set it without addingflutter_smooth_wheel_scrollyourself. It is that package's type: a breaking change to it there would be one here.- just_sonner now depends on
flutter_smooth_wheel_scroll^0.1.5, its first dependency beyond Flutter. Nothing to set up, and if your app installs itsSmoothWheelBindingwith a wheel scale, the deck follows that scale too.
0.4.2 #
- The deck takes the pointer only where it is drawn (#104). While the pointer held a deck that
could scroll, the deck kept the pointer in the band
offsetkeeps clear at its edge and a margin past the cap, where nothing of it was drawn: a click there did not reach your app, and a pointer moved there kept the deck fanned out with its timers stopped. Both bands are now your app's, before and after a scroll. - A deck with no cap is cut at the far edge's
offset(#104). WithdeckCap: () => null, a deck taller than the window was drawn into the bandoffsetkeeps clear on the far side, as 0.4.0 fixed at the near end (#86). It is now cut there, hard.
0.4.1 #
- The backdrop stays out of the
offsetband before the deck is scrolled too (#101). WithdeckBackdropset and the pointer resting on a deck that can scroll, the backdrop was drawn from the window's edge rather than fromoffset, over the band an app keeps clear for its own title bar, until a scroll cut it there. It is now cut at theoffsetedge whether the deck has scrolled or not, andDeckBackdrop.paddinggives way to it there. Clicks are unchanged. - The example app opens on a showcase (#29): every argument of
showand every part ofSonnerConfigon a control, grouped on one page, beside buttons that show toasts with them. The harness each behaviour was verified in is on a page of its own, behind the app bar.
0.4.0 #
-
Breaking: a toast with no timer is shown with
duration: null, notDuration.zero(#97). A toast shown with adurationis a transient toast and goes when it runs out; one shown withduration: nullstays until the user or your app dismisses it; one shown without adurationtakesconfig.durationas before.Duration.zeronow asserts in debug, onshow,updateandSonnerConfig, where it used to mean "no timer": writeduration: nullinstead.config.durationis aDuration?, set to null withcopyWith(duration: () => null), which makes every toast shown without a duration stay.update(id, duration: null)takes a toast's timer away, andToastContent(duration: null)makes apromiseresult stay. A function that passes a duration on toshownow needs a default: with a plainDuration? duration, every call that leaves it out passes null and shows a toast with no timer. Give itDuration? duration = SonnerConfig.configDuration. Apromise's loading content takes nodurationat all, andToastContent(duration: null)there now asserts as any other duration does. -
Breaking: the zone replaces stowing (#97).
toast.zoneis the layer the deck lives in, your app's to open and close, and it exists with no toast up. Its state is shown, open or hidden:zone.open()fans every toast out with no pointer, the ones beyondvisibleToastsincluded, with the controls past the far end, and pauses nothing. With no toast it draws a card reading "No notifications" (config.zoneEmpty, null for none, or a builder of your own). The last toast leaving does not close it.zone.close()returns to the stateopen()was called from, so a zone opened from hidden hides again — a title-bar notification button needs no other code.zone.hide()takes the deck out of sight with its toasts kept and counting down, asstow()did — but a new toast no longer brings the deck back: it shows the deck as a banner, the older toasts in it, until it has gone and the pointer has left, and the zone stays hidden. An empty zone stays hidden too.zone.reveal()brings it back.zone.heldsays whether the pointer holds the deck, and the controller notifies when it changes, so your app decides what closes the zone.
Removed:
stow(),unstow()andstowed, and the edge handle —stowHandle,DeckStowHandle,DeckStowHandleViewandDeckStowHandleBuilder; the entrance to a hidden zone is your app's own control. Renamed:stowControl→hideControlandstowMotion→hideMotion, withDeckStowControl,DeckStowLook,DeckStowView,DeckStowBuilder,DeckStowMotion,DeckStowMotionLook,DeckStowMotionViewandDeckStowMotionBuilder→DeckHide…; a view'sstowishide, and a motion view'sstowedishidden. The Hide control now also shows on an open zone with no toast, and on a banner it takes the banner down. New:SonnerZone,ZoneState,ZoneEmpty,ZoneEmptyViewandZoneEmptyBuilder, andSonnerConfig.configDurationfrom the entry above. -
Breaking: a drag a toast will not leave on moves it a little on either axis (#87). A toast on a centered deck used not to move at all when dragged sideways, since neither left nor right is a way out there, while a drag down on the same toast moved it a little and sprang back. Every drag the toast will not leave on is now damped that way, whichever axis it takes.
swipeDirections: {}changes meaning with it: it used to take the swipe away, and now lets no swipe dismiss while a drag still moves the toast and springs it back. To take the drag away altogether, make the toast notdismissible. -
A scrolled deck no longer draws over the
offsetband (#86). The deck is now cut at its near end as well as its far one. Scrolling a deck that overflows used to push toasts past the edge's ownoffsetand go on painting them there — over the band an app keeps clear for its own title bar, and off the layer. The near end sits at thatoffset, fades overDeckCap.fadeinward from it, and cuts hard where there is no fade; it does not need adeckCapat all, so a deck taller than the layer is cut there too. An exiting toast and the backdrop are cut with it. Clicks are unchanged: the near cut is paint only.
0.3.1 #
- The fanned-out deck can blur what is behind it (#78).
config.deckBackdropis null by default and draws nothing, so nothing changes until you ask for it. With aDeckBackdropthe deck softens what is behind it as it fans out under the pointer, and fades it back as it collapses:bluris the filter's sigma,dimandcolora cover over it (colornull follows the theme'scolorScheme.scrim),paddinghow far past the deck it reaches, andradiusits corners. A click in that padding still reaches your app — what it draws over claims no pointer the deck did not already claim. It blurs what your app painted, not the desktop behind your window.
0.3.0 #
- Breaking:
offsetis anEdgeInsets(#74). Each screen edge takes its own distance, so a deck can clear a title bar at the top and still sit close to the right edge. Writeoffset: EdgeInsets.all(24)where you wroteoffset: 24. The edges are physical. A centered position ignores left and right. The edge the position names holds the deck off it; the opposite one is where the expanded deck stops. - Nothing is drawn past the deck's cap while it stows (#75). With many toasts and a cap that
fades (the default), pressing Hide drew the oldest toasts past the cap for the first half of a
slideorshrinkstow. The fading cut now keeps them out, as a hard cut already did.
0.2.0 #
- A taller toast behind a shorter front keeps its whole card (#72). It is laid out at the front's height rather than cut to it, so its bottom edge and corners are drawn. Before, only the two side edges of its card peeked out past the front.
- Breaking for a builder: a builder is now laid out below its own height whenever its toast is
behind a shorter front. Wrap what is written on the card in the new
ToastFit, inside the card, or build the look with the newtoastCardBuilder, which takes the card and its content apart and also fades the content bycovered. A builder that does neither reports an overflow in debug, which fails a widget test showing toasts of mixed heights. In release the deck clips it, so nothing shows past the card.
0.1.0 #
First release. Desktop only: Windows, macOS and Linux.
- Toasts from anywhere.
toast.showneeds noBuildContextand returns aToastId.updatechanges a toast field by field;showat the id of a toast on screen replaces its content whole. Either way the toast keeps its place and counts down again.dismissanddismissAlltake toasts away. promise. One toast for the whole of a future: loading, then its result or its error. The future's own value or error goes back to the caller unchanged.- Two mount modes.
toast.attach(navigatorKey)draws the toasts in the root navigator's overlay, above dialogs and pages.SonnerHostwraps the app fromMaterialApp.builder. - The deck. Toasts stack into a deck that draws
visibleToastsof them and fans out, every toast drawn, while the pointer is over it. Six positions; width, gap and offset. - Timers pause while the pointer is over the deck, while a toast is dragged, and while the app is hidden. Toasts beyond the deck's window count down like the rest.
- Swipe to dismiss, in the directions the position names or the ones
swipeDirectionsgives. - A default look that follows the theme, light and dark, with a leading slot, an action slot,
a close button, and a spinner while a toast loads.
dismissiblegoverns every way a user dismisses a toast. - A builder that replaces the whole look, per toast or for every toast, handed a
ToastView: the toast's state, its animation, how much the deck covers it, its time left, anddismiss. - Time left, drawn by the default look as a border, a bar, or a ring, each with settings of
its own (
config.timeLeft). - A cap on the expanded deck (
config.deckCap, 400 px by default), past which the toasts scroll, with a draggable scrollbar beside them (config.scrollbar). - Dismiss all from the deck (
config.dismissAll): a pill or a header, or the app's own control through a builder. - Stow the deck:
stow()puts it out of sight, keeping its toasts, until the next new toast orunstow()brings it back. A control on the deck (config.stowControl), a motion (config.stowMotion) and a handle left at the edge (config.stowHandle), each with built-in looks and a builder. - Changing the config with toasts on screen, which the deck follows in place.