token_interceptor.dart 423 B

123456789101112131415
  1. import 'package:dio/dio.dart';
  2. import 'package:eitc_erm_dental_flutter/global.dart';
  3. //token拦截器
  4. class TokenInterceptor extends Interceptor {
  5. @override
  6. void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
  7. //如果存在token就添加到header里
  8. if (!options.headers.containsKey("token") && hasToken) {
  9. options.headers["token"] = token;
  10. }
  11. handler.next(options);
  12. }
  13. }