Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reza/accept_null_value_for_requests #312

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/basic_api/request.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Request extends Equatable {
this.msgType,
this.passthrough,
this.reqId,
this.acceptNullValue = false,
});

/// Generate an instance from JSON.
Expand All @@ -25,6 +26,9 @@ class Request extends Equatable {
/// [Optional] Used to map request to response.
final int? reqId;

/// Determine accept null value in request or not.
final bool acceptNullValue;

/// Converts an instance to JSON.
Map<String, dynamic> toJson() => <String, dynamic>{
'passthrough': passthrough,
Expand All @@ -35,10 +39,12 @@ class Request extends Equatable {
Request copyWith({
Map<String, dynamic>? passthrough,
int? reqId,
bool? acceptNullValue,
}) =>
Request(
passthrough: passthrough ?? this.passthrough,
reqId: reqId ?? this.reqId,
acceptNullValue: acceptNullValue ?? false,
);

/// Override equatable class.
Expand Down
9 changes: 7 additions & 2 deletions lib/services/connection/call_manager/base_call_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,13 @@ abstract class BaseCallManager<T> {
required Request request,
required bool isSubscription,
}) {
final Map<String, dynamic> result = request.toJson()
..removeWhere((String key, dynamic value) => value == null);
final Map<String, dynamic> result;
if (request.acceptNullValue) {
result = request.toJson();
} else {
result = request.toJson()
..removeWhere((String key, dynamic value) => value == null);
}

if (isSubscription) {
result.putIfAbsent('subscribe', () => 1);
Expand Down
Loading