MockKit class

The central façade for flutter_mockkit.

Use MockKit to register routes, toggle mock/live mode, and configure global behaviour such as default latency and verbose logging.

Basic setup

void main() {
  MockKit.enable();

  MockKit.register(
    MockRoute(
      method: HttpMethod.get,
      path: '/ping',
      response: MockResponse.ok({'status': 'ok'}),
    ),
  );

  runApp(MyApp());
}

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

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 Properties

globalDelay Duration
The current global delay added to every mock response.
no setter
isEnabled bool
Whether mock mode is currently active.
no setter
isLoggingEnabled bool
Whether verbose logging is active.
no setter
routes List<MockRoute>
Returns an unmodifiable view of all currently registered routes.
no setter

Static Methods

clearAll() → void
Removes all registered routes.
disable() → void
Disables mock mode. Interceptors pass requests through to the real network.
disableLogging() → void
Disables verbose console logging.
enable() → void
Enables mock mode. All intercepted requests will be matched against registered MockRoutes instead of hitting real network endpoints.
enableLogging() → void
Enables verbose console logging for every intercepted request and its matched mock response. Useful during development.
register(MockRoute route) → void
Registers a single MockRoute.
registerAll(List<MockRoute> routes) → void
Registers multiple MockRoutes in one call.
resolve(HttpMethod method, String requestPath, {Map<String, String> queryParameters = const {}, Map<String, String> headers = const {}, String? body}) Future<MockResponse?>
Resolves a mock response for the given method and requestPath, or returns null if no matching route exists.
setGlobalDelay(Duration delay) → void
Sets a global artificial delay applied to all mock responses in addition to any per-route MockResponse.delay.
unregister(HttpMethod method, String path) → void
Removes a previously registered route by method + path.