bloc_plus 0.3.1
bloc_plus: ^0.3.1 copied to clipboard
Extensions for flutter_bloc focused on ergonomics and safety.
0.3.1 #
- Added:
debugPrintUnheardEffects: set it totrueandemitEffectprints a warning in debug builds for an effect that nothing listens to. Effects are not replayed, so such an effect is lost, for example one emitted from the bloc's constructor or before the listening widget is mounted. Off by default; release builds never print it.- README: a recipe for testing effects in unit and widget tests.
Migration impact:
- None.
Release type rationale:
patch: one additive, opt-in debug flag (a new public top-level variable) and docs; nothing changes unless the flag is set. Under the 0.x convention^0.3.0already allows it; code that uses the flag needs^0.3.1.
0.3.0 #
- Added:
BlocCondition<S>andwhenChanged(selector, {equals}). The result goes straight intobuildWhen,listenWhenandselectorShouldRebuild, also onBlocBuilder,BlocListenerandBlocConsumer, without type arguments when the widget has its own. Select a record for several fields; passequals:for collections.BlocEffectListener<B extends EffectsSource<E>, E>: a wrong effect type or a bloc without effects no longer compiles, and the listener composes insideMultiBlocListener.RestartableTask.runOutcomeandRestartableTasksMixin.runLatestOutcome: the task gets aCancellationToken, and theTaskOutcome<T>result tells a cancelled run apart from one that completed withnull.CancellationToken.whenCancelledcan abort the underlying I/O.BlocConsumerWithEffects.listeneris optional.- A
constconstructor forBlocListenerWithBloc.
- Changed:
- A cancelled, superseded or closed run releases its caller at once (
nullorTaskOutcome.cancelled()) instead of waiting for the abandoned work, which keeps running. This fixes callers that hung on work that never completes. BlocConsumerWithEffectsrequiresB extends HasEffects<S, E>.- The
*WithBlocwidgets and their callback typedefs acceptB extends StateStreamable<S>, like flutter_bloc's widgets.readOrNull,watchOrNullandwithBlocaccept any provided type, such as a repository:withBloc((Repo repo) => ...)now finds the repository instead of inferringNeverand returningnull.selectOrNullaccepts anyStateStreamableSource<S>, the typeBlocProviderprovides and keeps up to date. BlocConsumerWithBlocandBlocConsumerWithEffectsresolve the bloc once per build, so states, effects and every callback come from one instance, also right afterbloc:changes from an instance tonull.emitEffectandsafeEmitare@protectedand@visibleForTesting, likeemit.- New direct dependency:
provider>=6.0.0 <7.0.0, the rangeflutter_blocalready requires.
- A cancelled, superseded or closed run releases its caller at once (
- Deprecated, removed in 1.0:
RebuildPolicy,ListenPolicyand their 12 factories (includingwhenListen, which clashes withbloc_test),EffectListener,MultiEffectListenerandSingleChildEffectListener.
Migration impact:
- Deprecated APIs keep working; each use is a
deprecated_member_useinfo, which failsflutter analyzeuntil migrated:onChange(sel)/onChangeListen(sel)->whenChanged(sel), keeping<S, T>when the widget has no type arguments; the...Byforms ->whenChanged(sel, equals: eq);whenRebuild(p)/whenListen(p)->p;always()-> omit the parameter;never()->(previous, current) => false;distinct()->(previous, current) => previous != current(omitting the parameter differs only for a first emitted state equal to the initial one);a.and(b)-> a plain predicate or a record selector.EffectListener<B, S, E>->BlocEffectListener<B, E>;MultiEffectListener->MultiBlocListener, which needs a non-empty list; a listener for one effect subtype -> the supertype withif (effect case Sub(...))inonEffect.- With
bloc_test, importbloc_pluswithhide whenListenuntil 1.0.
BlocConsumerWithEffectsno longer compiles with a bloc that implementsEffectsSourceby hand: mix inHasEffects<S, E>.emitEffectandsafeEmitcalled from outside the bloc, extension methods on it included, now warn (tests are exempt): move the call into the bloc or into amixin X on HasEffects<S, E>.- Code after the
awaitof a superseded run, afinallyincluded, now runs while the newer run is in flight: check the outcome before resetting a shared loading flag. - In a
Blochandler, a task that calls the handler'semitstill needs anemit.isDone(ortoken.isCancelled) check: the handler now completes first, and bloc rejects the lateemitonly with an assert, so release builds emit the stale state. - Write both type arguments of
BlocEffectListener: below language version 3.7,Eis not inferred frombloc:. - After
bloc:ofBlocConsumerWithBlocorBlocConsumerWithEffectschanges from an instance tonull, the widget follows the provided bloc at once instead of the previous instance.BlocBuilderWithBlocandBlocListenerWithBlockeep the previous instance, likeBlocBuilderandBlocListener, while their callback gets the provided one: give them a newkeywhen you switch.
Release type rationale:
minor: new APIs, wider type bounds and deprecations; the narrower consumer bound, the new analyzer warnings, the earlier release of superseded callers and the consumers following the provided bloc are behaviour changes that a 0.x minor allows.
0.2.2 #
- Fixes:
CancellationToken.run,RestartableTask.run,runLatestandguardeddrop the failure of superseded or cancelled work like its result; only the latest run can throw.guardedno longer starts on a closed bloc.HasEffects.close()no longer waits for a paused effect subscriber before closing the bloc.BlocSelectorWithBlocbehaves likeBlocSelector: no stale value after the selector changes, one selector call per state change, andselectorShouldRebuildgets the last built value asprevious.readOrNull,watchOrNullandselectOrNullreturnnullonly when no provider exists.runLatestdrops the keys of failed tasks; a repeatedclose()waits for the first one.bloclower bound raised to9.2.1, sosafeEmitandguardedalso stop on a closingBloc.
- Tooling: Flutter 3.50 support (
flutter_lints^6.0.0, contributors need Dart 3.8; example app onmaterial_ui, Flutter >=3.47), one gated CI workflow that also checks the lowest dependency versions and Flutter 3.10.6, contract tests and clearer API docs. Package minimums stay at Dart 3.0 and Flutter 3.10.
Migration impact:
- No API changes; if you pin
blocbelow9.2.1, upgrade within9.x. - Superseded or cancelled runs, and
guardedcalls that fail after close, returnnullinstead of throwing. - Effects emitted right before
close()reach subscribers after the bloc is closed, like its last states; a subscriber that emits into the bloc in response should usesafeEmit. selectorShouldRebuildgets the last built value asprevious;BlocSelectorWithBlocis now aStatefulWidget.- A missing provider read inside a bloc's
createnow throws fromreadOrNull/watchOrNull/selectOrNullinstead of returningnull.
Release type rationale:
patch: bug fixes without API changes.
0.2.1 #
- Compatibility metadata update:
- lowered the developer tooling floor from
Dart 3.8toDart 3.0by constrainingflutter_lintsto the latest line that still supports Dart 3.0 - kept the package minimum SDKs unchanged at
Dart >=3.0.0andFlutter >=3.10.0
- lowered the developer tooling floor from
Migration impact:
- No API changes. No migration required.
Release type rationale:
patchchange for compatibility metadata and tooling support only.
0.2.0 #
- Added policy composition and custom equality helpers:
whenRebuildwhenListenRebuildPolicy.and,RebuildPolicy.or,RebuildPolicy.notListenPolicy.and,ListenPolicy.or,ListenPolicy.notonChangeByonChangeListenBy
- Expanded effect ergonomics:
- added
effectWhentoEffectListener - added
MultiEffectListener
- added
- Added higher-level async helpers:
RestartableTasksMixin- keyed
runLatest,cancelLatest,cancelAllLatest,isTaskRunning
- Added
BlocConsumerWithEffectsfor combined state and effect composition. - Updated README, PRD, task specs, and example app to document the new APIs.
Migration impact:
- No breaking API changes. Existing code continues to work.
- Consumers can adopt the new APIs incrementally.
Release type rationale:
minorbump for new public API surface additions.
0.1.3 #
- Documentation improvements:
- Added dartdoc comments for the public API to improve generated package docs and pub.dev documentation coverage.
Migration impact:
- No API changes. No migration required.
Release type rationale:
patchbump for user-visible documentation improvements with no behavior changes.
0.1.2 #
- Documentation cleanup:
- Removed the two trailing README sections:
StatusandRelease process (without verified publisher).
- Removed the two trailing README sections:
- Change category:
chore
Migration impact:
- No API changes. No migration required.
Release type rationale:
patchbump for documentation-only cleanup.
0.1.1 #
- CI improvements:
- Added dedicated coverage workflow with Codecov upload.
- Coverage upload now supports
CODECOV_TOKENvia GitHub Actions secret.
- Release process improvements:
- Added PR quality and release automation workflows.
- Added manual publish workflow for non-verified publisher setup.
- Documentation improvements:
- Added status badges to README.
- Clarified release flow and publish steps.
Migration impact:
- No API changes. No migration required.
Release type rationale:
patchbump for CI, release automation, and documentation improvements.
0.1.0 #
- Added
ui_with_blocmodule:BlocBuilderWithBlocBlocListenerWithBlocBlocConsumerWithBlocBlocSelectorWithBloc
- Added
context_extensionsmodule:readOrNullwatchOrNullselectOrNullwithBloc
- Added
policiesmodule:- Rebuild policies:
distinct,onChange,always,never - Listen policies:
distinctListen,onChangeListen,alwaysListen,neverListen
- Rebuild policies:
- Added
async_safetymodule:SafeEmitMixinCancellationTokenRestartableTask
- Added
effectsmodule:HasEffectsEffectListener
Migration impact:
- First feature release, no migration required.
Release type rationale:
minorbump due to new public API surface additions.