Skip to content

Commit

Permalink
🔊 Raise warning for Map datas
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexV525 committed Sep 23, 2023
1 parent 9a63c37 commit 124d3cf
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions dio/lib/src/transformers/sync_transformer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import '../adapter.dart';
import '../headers.dart';
import '../options.dart';
import '../transformer.dart';
import '../utils.dart';

@Deprecated('Use BackgroundTransformer instead')
typedef DefaultTransformer = SyncTransformer;
Expand Down Expand Up @@ -33,8 +34,18 @@ class SyncTransformer extends Transformer {
final dynamic data = options.data ?? '';
if (data is! String && Transformer.isJsonMimeType(options.contentType)) {
return jsonEncodeCallback(data);
} else if (data is Map<String, dynamic>) {
return Transformer.urlEncodeMap(data, options.listFormat);
} else if (data is Map) {
if (data is Map<String, dynamic>) {
return Transformer.urlEncodeMap(data, options.listFormat);
}
debugLog(
'The data is a type of Map (${data.runtimeType}), '
'but the transformer can only encode Map<String, dynamic>.\n'
'If you are writing maps using `{}`, '
'consider writing `<String, dynamic>{}`.',
StackTrace.current,
);
return data.toString();
} else {
return data.toString();
}
Expand Down

0 comments on commit 124d3cf

Please sign in to comment.