AroundMethodInterceptor class abstract interface

A comprehensive interceptor that wraps the entire method invocation process, allowing developers to control when and how the target method executes.

This is the most powerful interceptor type, capable of replacing, augmenting, or conditionally bypassing method execution entirely.

Common Use Cases

  • Transaction boundaries
  • Retry mechanisms
  • Execution time measurement
  • Security or context wrapping

Example

class TimingInterceptor implements AroundMethodInterceptor {
  @override
  bool canIntercept(Method method) => true;

  @override
  Future<T?> aroundInvoke<T>(MethodInvocation<T> invocation) async {
    final start = DateTime.now();
    final result = await invocation.proceed();
    final end = DateTime.now();
    print("Execution time: ${end.difference(start).inMilliseconds} ms");
    return result;
  }
}

Invocation Lifecycle

  1. aroundInvocation is invoked before method execution.
  2. Interceptor decides whether to call invocation.proceed().
  3. Can optionally modify the return value or handle exceptions.

See Also

Implemented types

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

aroundInvocation<T>(MethodInvocation<T> invocation) Future<T?>
Invoked around the target method execution, allowing interception both before and after invocation.
canIntercept(Method method) bool
Determines whether this interceptor can intercept the specified method.
inherited
equalizedProperties() List<Object?>
Mixin-style contract for value-based equality, hashCode, and toString.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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