dreampad/lib/app/api/interceptors/request_interceptor.dart

22 lines
630 B
Dart
Raw Permalink Normal View History

2023-11-28 10:44:58 +08:00
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;
}