RestAPIService<DataType extends Jsonable<Object>> constructor

RestAPIService<DataType extends Jsonable<Object>>({
  1. RestAPI? restAPI,
  2. DataType? dataType,
  3. String? token,
  4. String? apiKey,
  5. required String baseUrl,
  6. Duration? connectTimeout,
  7. Duration? receiveTimeout,
  8. Duration? sendTimeout,
  9. HttpClientAdapter? httpClientAdapter,
  10. Map<String, dynamic>? headers,
  11. TokenCallback? tokenCallback,
  12. CancelTokenCallback? cancelTokenCallback,
  13. List<Interceptor>? interceptors,
})

Implementation

RestAPIService({
  RestAPI? restAPI,
  this.dataType,
  String? token,
  String? apiKey,
  required String baseUrl,
  Duration? connectTimeout,
  Duration? receiveTimeout,
  Duration? sendTimeout,
  dio.HttpClientAdapter? httpClientAdapter,
  Map<String, dynamic>? headers,
  TokenCallback? tokenCallback,
  CancelTokenCallback? cancelTokenCallback,
  List<dio.Interceptor>? interceptors,
}) : assert(
       (((token?.isNotEmpty ?? false) && tokenCallback == null) ||
               ((token?.isEmpty ?? true) && tokenCallback != null)) ||
           (apiKey?.isNotEmpty ?? false),
       '\n\nA token or tokenCallback must be specified, only one of both.'
       '\nOtherwise an apiKey must be specified.',
     ),
     restAPI = restAPI ?? RestAPI() {
  this.restAPI.init(
    apiKey: apiKey,
    baseUrl: baseUrl,
    connectTimeout: connectTimeout,
    receiveTimeout: receiveTimeout,
    sendTimeout: sendTimeout,
    httpClientAdapter: httpClientAdapter,
    headers: headers,
    tokenCallback:
        tokenCallback ?? (token == null ? null : (() async => token)),
    cancelTokenCallback: cancelTokenCallback,
    interceptors: interceptors,
  );
}