작성
·
165
0
import 'package:code_factory/restaurant/model/restaurant_detail_model.dart';
import 'package:dio/dio.dart' hide Headers;
// import 'package:retrofit/http.dart';
import 'package:retrofit/retrofit.dart';
part 'restaurant_repository.g.dart';
@RestApi()
abstract class RestaurantRepository {
factory RestaurantRepository(Dio dio, {String baseUrl}) =
_RestaurantRepository;
@GET('/{id}')
@Headers({'accessToken' : 'true'})
Future<RestaurantDetailModel> getRestaurantDetail({
@Path() required String id,
});
}
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'restaurant_repository.dart';
// **************************************************************************
// RetrofitGenerator
// **************************************************************************
// ignore_for_file: unnecessary_brace_in_string_interps,no_leading_underscores_for_local_identifiers
class _RestaurantRepository implements RestaurantRepository {
_RestaurantRepository(
this._dio, {
this.baseUrl,
});
final Dio _dio;
String? baseUrl;
@override
Future<RestaurantDetailModel> getRestaurantDetail(
{required String id}) async {
const _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{};
final _headers = <String, dynamic>{r'accessToken': 'true'};
_headers.removeWhere((k, v) => v == null);
final Map<String, dynamic>? _data = null;
final _result = await _dio.fetch<Map<String, dynamic>>(
_setStreamType<RestaurantDetailModel>(Options(
method: 'GET',
headers: _headers,
extra: _extra,
)
.compose(
_dio.options,
'/${id}',
queryParameters: queryParameters,
data: _data,
)
.copyWith(
baseUrl: _combineBaseUrls(
_dio.options.baseUrl,
baseUrl,
))));
final value = RestaurantDetailModel.fromJson(_result.data!);
return value;
}
RequestOptions _setStreamType<T>(RequestOptions requestOptions) {
if (T != dynamic &&
!(requestOptions.responseType == ResponseType.bytes ||
requestOptions.responseType == ResponseType.stream)) {
if (T == String) {
requestOptions.responseType = ResponseType.plain;
} else {
requestOptions.responseType = ResponseType.json;
}
}
return requestOptions;
}
String _combineBaseUrls(
String dioBaseUrl,
String? baseUrl,
) {
if (baseUrl == null || baseUrl.trim().isEmpty) {
return dioBaseUrl;
}
final url = Uri.parse(baseUrl);
if (url.isAbsolute) {
return url.toString();
}
return Uri.parse(dioBaseUrl).resolveUri(url).toString();
}
}
생성된 repository.g.dart 파일을 보시면
final _headers = <String, dynamic>{r'accessToken': 'true'};
accessToken 앞에 계속 r 이 붙습니다.
왜이럴까요..
넵 통신은 정상이지만 헤더에서 찾을 때 r'accessToken' 으로 찾아야 해서요
파일 생성시에 고칠 수 있는 방법은 없을까요>