Skip to content

Commit 1dd4c06

Browse files
committed
fix: handle null data in POST requests on web
- Use empty map for null data on web
1 parent f0b3b7b commit 1dd4c06

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

lib/src/ht_http_client.dart

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ class HtHttpClient {
3333
required bool isWeb,
3434
Dio? dioInstance,
3535
List<Interceptor>? interceptors,
36-
}) : _dio = dioInstance ?? Dio() {
36+
}) : _dio = dioInstance ?? Dio(),
37+
_isWeb = isWeb {
3738
// Configure base options
3839
final baseOptions = BaseOptions(
3940
baseUrl: baseUrl,
@@ -64,9 +65,12 @@ class HtHttpClient {
6465
// );
6566
}
6667

67-
/// The configured Dio instance used for making requests.
68+
/// The Dio instance used for making requests.
6869
final Dio _dio;
6970

71+
/// Flag indicating if the client is operating in a web environment.
72+
final bool _isWeb;
73+
7074
/// Performs a GET request.
7175
///
7276
/// - [path]: The endpoint path appended to the "baseUrl".
@@ -120,10 +124,14 @@ class HtHttpClient {
120124
Options? options,
121125
CancelToken? cancelToken,
122126
}) async {
127+
dynamic dataToSend = data;
128+
if (_isWeb && dataToSend == null) {
129+
dataToSend = <String, dynamic>{}; // Use an empty map for null data on web
130+
}
123131
try {
124132
final response = await _dio.post<T>(
125133
path,
126-
data: data,
134+
data: dataToSend,
127135
queryParameters: queryParameters,
128136
options: options,
129137
cancelToken: cancelToken,

0 commit comments

Comments
 (0)