MiddlewareComposer<R, A> class

Helper class for easy composition with hook functions.

Use it as Middleware like this:

final middleware = MiddlewareComposer<foo, bar>(
  onRun: (final arg) async => arg,
  onReturn: (final arg, final response) async => response,
  onError: (final error, final stackTrace, final arg) async =>
      Error.throwWithStackTrace(error, stackTrace),
).middleware;
Inheritance
Implementers

Constructors

MiddlewareComposer({OnRun<A>? onRun, OnReturn<R, A>? onReturn, OnError<R, A>? onError, OnFinally<A>? onFinally})
Compose a middleware with one or more hook functions.
const

Properties

hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

middleware(Handler<FutureOr<R>, A> next) → Handler<FutureOr<R>, A>
Middleware method that produces the handler that runs these hooks. Adheres to the Middleware signature.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onError(Object error, StackTrace stackTrace, A arg) → FutureOr<R>
Hook method that is called if the next handler throws.
override
onFinally(A arg) → FutureOr<void>
Hook method that is called after the next handler returns or throws, after the onReturn / onError hook has run.
override
onReturn(A arg, R response) → FutureOr<R>
Hook method that is called after the next handler returns normally.
override
onRun(A arg) → FutureOr<A>
Hook method that is called before the next handler is run.
override
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited