dreampad/lib/app/api/interceptors/request_interceptor.dart
2023-11-28 10:45:09 +08:00

22 lines
630 B
Dart

import 'dart:async';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get_connect/http/src/request/request.dart';
import 'package:sp_util/sp_util.dart';
import 'package:dreampad/app/shared/constants/constants.dart';
FutureOr<Request> requestInterceptor(request) async {
final token = SpUtil.getString(Constant.accessToken);
if (token!.isNotEmpty) {
request.headers['Authorization'] = 'Bearer $token';
}
if (!SmartDialog.config
.checkExist(dialogTypes: {SmartAllDialogType.loading})) {
SmartDialog.showLoading(msg: '正在努力加载中…');
}
return request;
}