NetworkClient class abstract

Abstract HTTP client interface for making network requests.

This interface allows using different HTTP client implementations (http package, Dio, custom implementations) with the payment providers.

Default Implementation

The package provides HttpNetworkClient as the default implementation using the http package.

Custom Implementation Example (Dio)

class DioNetworkClient implements NetworkClient {
  DioNetworkClient({Dio? dio}) : _dio = dio ?? Dio();
  final Dio _dio;

  @override
  Future<NetworkResponse> post(
    String url, {
    Map<String, String>? headers,
    dynamic body,
    Duration? timeout,
  }) async {
    final response = await _dio.post(
      url,
      data: body,
      options: Options(
        headers: headers,
        sendTimeout: timeout,
        receiveTimeout: timeout,
      ),
    );
    return NetworkResponse(
      statusCode: response.statusCode ?? 0,
      body: response.data?.toString() ?? '',
      headers: response.headers.map.map((k, v) => MapEntry(k, v.join(','))),
    );
  }

  // ... implement other methods
}

Using Custom Client with Providers

final dioClient = DioNetworkClient();
final provider = IyzicoProvider(networkClient: dioClient);
await provider.initialize(config);
Implementers
Available extensions

Constructors

NetworkClient()

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

delete(String url, {Map<String, String>? headers, Duration? timeout}) Future<NetworkResponse>
Performs an HTTP DELETE request.
dispose() → void
Releases any resources held by the client.
get(String url, {Map<String, String>? headers, Duration? timeout}) Future<NetworkResponse>
Performs an HTTP GET request.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
post(String url, {Map<String, String>? headers, dynamic body, Duration? timeout}) Future<NetworkResponse>
Performs an HTTP POST request.
postForm(String url, {Map<String, String>? headers, Map<String, String>? fields, Duration? timeout}) Future<NetworkResponse>
Performs an HTTP POST request with form-encoded body.
put(String url, {Map<String, String>? headers, dynamic body, Duration? timeout}) Future<NetworkResponse>
Performs an HTTP PUT request.
toString() String
A string representation of this object.
inherited
withResilience({required String circuitName, ResilienceConfig config = const ResilienceConfig(), ResilienceCallback? onEvent}) ResilientNetworkClient

Available on NetworkClient, provided by the ResilientNetworkClientExtension extension

Wrap this client with resilience features.

Operators

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