The argument type 'void Function(DioError)' can't be assigned to the parameter type 'void Function(DioError, ErrorInterceptorHandler)?'

2,225
initializeInterceptor(){
    _dio.interceptors.add(InterceptorsWrapper(
        onError: (error, errorInterceptorHandler ){
          print(error.message);
        },
        onRequest: (request, requestInterceptorHandler){
          print("${request.method} | ${request.path}");
        },
        onResponse: (response, responseInterceptorHandler) {
          print('${response.statusCode} ${response.statusCode} ${response.data}');
        }
    ));
  }
Share:
2,225
Admin
Author by

Admin

Updated on December 28, 2022

Comments

  • Admin
    Admin over 1 year

    so I'm wrapping my HTTP requests with a few simple functions. Like Following:

    import 'package:dio/dio.dart';
    
    class HttpService {
      late Dio _dio;
    
      final String baseUrl = "http://10.0.2.2:8080/community";
    
      HttpService() {
        _dio = Dio(BaseOptions(
          baseUrl: baseUrl,
        ));
    
        // initializaInterceptors();
      }
    
      Future<Response> getRequest(String endPoint) async {
        Response response;
        try {
          response = await _dio.get(endPoint);
        } on DioError catch (e) {
          print(e.message);
          throw Exception(e.message);
        }
    
        return response;
      }
    
      Future<Response> postRequest(String endPoint) async {
        Response response;
        try {
          response = await _dio.post(endPoint);
        } on DioError catch (e) {
          print(e.message);
          throw Exception(e.message);
        }
    
        return response;
      }
    
      initializaInterceptors() {
          _dio.interceptors.add(InterceptorsWrapper(onError: (error) {
            print(error.message);
          }, onRequest: (request) {
            print("${request.method} ${request.path}");
          }, onResponse: (response) {
            print(response.data);
          }));
        }
      }
    }
    

    It works fine in the past months. However, it just pops an error in initializaInterceptors() function:

    The argument type 'void Function(DioError)' can't be assigned to the parameter type 'void Function(DioError, ErrorInterceptorHandler)?'. The argument type 'void Function(RequestOptions)' can't be assigned to the parameter type 'void Function(RequestOptions, RequestInterceptorHandler)?'. The argument type 'void Function(Response)' can't be assigned to the parameter type 'void Function(Response, ResponseInterceptorHandler)?'.

    Does anyone know what is going on? Thanks