Files
FlutterUnit/lib/app/utils/http_utils/token_interceptor.dart
2021-01-24 08:10:16 +08:00

22 lines
477 B
Dart

import 'package:dio/dio.dart';
const String _kTokenKey = 'Authorization';
const String _kTokenPrefix = 'Bearer ';
class TokenInterceptors<T> extends InterceptorsWrapper {
String token;
TokenInterceptors({this.token=''});
@override
Future onRequest(RequestOptions options) async{
// print('----RequestOptions---${options.path}------------');
if(token.isNotEmpty){
options.headers[_kTokenKey] = '$_kTokenPrefix$token';
}
return options;
}
}