async_zone 0.1.0
async_zone: ^0.1.0 copied to clipboard
Declarative async and error handling for Flutter inspired by React Suspense and Error Boundary. Throw futures during build to suspend the surrounding AsyncZone and show its fallback.
0.1.0 #
Initial release.
Features #
AsyncZonewidget that renders a fallback while descendants are suspended on a pendingFuture, inspired by React Suspense. Exposesalignmentandfitto control the internalStacklayout.ZoneWidgetandStatefulZoneWidgetbase classes, plus the inlineZoneBuilder, for usingAsyncZone.of(context).use(future)during build.AsyncZone.ofthrows a descriptiveFlutterErrorboth when noAsyncZoneancestor exists and when called from an element that does not mix inZoneElement.- Identity-based caching: repeated
use()calls with the sameFutureinstance return the resolved value without re-suspending, and entries are reclaimed automatically when the future is no longer referenced. - Pending futures are superseded when the calling element rebuilds with a new future or is unmounted, so stale completions never replace fresh results.
- Sliver-shaped variants
SliverZoneWidget,SliverStatefulZoneWidget, andSliverZoneBuilder, plus theSliverZoneElementMixinfor composing custom sliver elements withZoneElement. - Low-level
ErrorZoneWidget/StatefulErrorZoneWidgetbase classes with React-stylegetDerivedStateFromError,componentDidCatch,resetErrorBoundary, andshowErrorBoundary, plus theErrorBoundaryMixinandErrorZoneElementfor composing the lifecycle into custom widgets. - Errors thrown inside an inner error zone's fallback (or by
ZoneWidgetdescendants of that fallback) escalate to the next outer error zone, mirroring React's error boundary semantics. TransitionZoneBridge/TransitionZoneProviderbridge interface that lets external coordinators (such as the companionasync_transition_boundarypackage) keep the previous subtree visible while a new state suspends.
Documentation #
- Bilingual README (English / Japanese), architecture overview, and dartdoc with runnable examples for every public API.