This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
final response = await _dio!.request( | |
request.path, | |
data: body, | |
queryParameters: request.queryParams, | |
options: Dio.Options( | |
method: request.type.name, | |
headers: {..._headers, ...(request.headers ?? {})}, // Combine all headers | |
), | |
onSendProgress: onSendProgress, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void addBasicAuth(String accessToken) { | |
_headers['Authorization'] = 'Bearer $accessToken'; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class _PreparedNetworkRequest<Model> { | |
const _PreparedNetworkRequest( | |
this.request, | |
this.parser, | |
this.dio, | |
this.headers, | |
this.onSendProgress, | |
this.onReceiveProgress, | |
); | |
final NetworkRequest request; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Future<NetworkResponse<Model>> executeRequest<Model>( | |
_PreparedNetworkRequest request, | |
) async { | |
try { | |
dynamic body = request.request.data.whenOrNull( | |
json: (data) => data, | |
text: (data) => data, | |
); | |
final response = await request.dio.request( | |
request.request.path, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final req = _PreparedNetworkRequest<Model>( | |
request, | |
parser, | |
_dio!, | |
{..._headers, ...(request.headers ?? {})}, | |
onSendProgress, | |
onReceiveProgress, | |
); | |
final result = await compute( | |
executeRequest<Model>, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class NetworkService { | |
NetworkService({ | |
required this.baseUrl, | |
dioClient, | |
httpHeaders, | |
}) : this._dio = dioClient, | |
this._headers = httpHeaders ?? {}; | |
Dio? _dio; | |
final String baseUrl; | |
Map<String, String> _headers; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:freezed_annotation/freezed_annotation.dart'; | |
import 'dart:io'; | |
part 'NetworkRequestBody.freezed.dart'; | |
part 'NetworkResponse.freezed.dart'; | |
class AccessTokenResponse { | |
String? accessToken; | |
AccessTokenResponse.fromJson(Map<String, dynamic> json) { | |
accessToken = json['access_token']; |
OlderNewer