NetworkFilterChain<T> class

Immutable, ordered chain of NetworkFilters with short-circuit evaluation.

The chain runs filters in insertion order and stops at the first false. An empty chain permits everything (returns true).

Chains are value-like: add and merge return new instances.

Example:

// Build a chain that logs only successful (2xx) GET/POST responses.
final chain = NetworkFilterChain<Response<dynamic>>([
  const StatusCodeFilter.successOnly(),
  const HttpMethodFilter({'GET', 'POST'}),
]);

if (chain.apply(response)) {
  logger.logNetworkResponse(response);
}

// Extend an existing chain:
final sampled = chain.add(const SamplingFilter(0.1));

Constructors

NetworkFilterChain(List<NetworkFilter<T>> filters)
Creates a chain from an ordered list of filters.
const
NetworkFilterChain.empty()
Creates an empty chain that permits all events.
const
NetworkFilterChain.fromPredicate(bool predicate(T))
Wraps a legacy bool Function(T) callback as a single-filter chain.
factory

Properties

hashCode → int
The hash code for this object.
no setterinherited
isEmpty → bool
Whether this chain contains no filters.
no setter
length → int
The number of filters in this chain.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

add(NetworkFilter<T> filter) → NetworkFilterChain<T>
Returns a new chain with filter appended.
apply(T value) → bool
Runs all filters in order. Returns false on the first failing filter (short-circuit). An empty chain returns true.
merge(NetworkFilterChain<T> other) → NetworkFilterChain<T>
Returns a new chain combining this chain's filters with other's.
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

Static Methods

any<T>(List<NetworkFilter<T>> filters) → NetworkFilter<T>
Creates an OR-combinator filter: passes if any filter returns true.