encodeJson function

Expression? encodeJson(
  1. ClientType type,
  2. String variable
)

Implementation

Expression? encodeJson(ClientType type, String variable) {
  final toJson = convertToJson(type, refer(variable));

  final shouldEncode = shouldEncodeJson(type);

  if (shouldEncode == null) {
    return null;
  }

  if (shouldEncode case false) {
    return toJson;
  }

  return refer('jsonEncode').call([toJson ?? refer(variable)]);
}