title: Using Interceptor in Dio for Flutter to Refresh Token
body: <p>I am trying to use Interceptor with Dio in flutter, I have to handle Token expire.
  following is my code </p>
  
  <pre class="lang-dart prettyprint-override"><code>Future&lt;Dio&gt; getApiClient() async {
      token = await storage.read(key: USER_TOKEN);
      _dio.interceptors.clear();
      _dio.interceptors
          .add(InterceptorsWrapper(onRequest: (RequestOptions options) {
        // Do something before request is sent
        options.headers["Authorization"] = "Bearer " + token;
        return options;
      },onResponse:(Response response) {
          // Do something with response data
          return response; // continue
      }, onError: (DioError error) async {
        // Do something with response error
        if (error.response?.statusCode == 403) {
          // update token and repeat
          // Lock to block the incoming request until the token updated
  
          _dio.interceptors.requestLock.lock();
          _dio.interceptors.responseLock.lock();
          RequestOptions options = error.response.request;
          FirebaseUser user = await FirebaseAuth.instance.currentUser();
          token = await user.getIdToken(refresh: true);
          await writeAuthKey(token);
          options.headers["Authorization"] = "Bearer " + token;
  
          _dio.interceptors.requestLock.unlock();
          _dio.interceptors.responseLock.unlock();
          _dio.request(options.path, options: options);
        } else {
          return error;
        }
      }));
      _dio.options.baseUrl = baseUrl;
      return _dio;
    }
  </code></pre>
  
  <p>problem is instead of repeating the network call with the new token, Dio is returning the error object to the calling method, which in turn is rendering the wrong widget, any leads on how to handle token refresh with dio?</p>