createFlag method

Future<Response<Flag>> createFlag (
  1. CreateFlagRequest body,
  2. {CancelToken cancelToken,
  3. Map<String, String> headers}
)

Implementation

Future<Response<Flag>> createFlag(
  CreateFlagRequest body, {
  CancelToken cancelToken,
  Map<String, String> headers,
}) async {
  String _path = "/flags";

  Map<String, dynamic> queryParams = {};
  Map<String, String> headerParams = Map.from(headers ?? {});
  dynamic bodyData;

  queryParams.removeWhere((key, value) => value == null);
  headerParams.removeWhere((key, value) => value == null);

  List<String> contentTypes = ["application/json"];

  var serializedBody = _serializers.serialize(body);
  var jsonbody = json.encode(serializedBody);
  bodyData = jsonbody;

  return _dio
      .request(
    _path,
    queryParameters: queryParams,
    data: bodyData,
    options: Options(
      method: 'post'.toUpperCase(),
      headers: headerParams,
      extra: {
        'secure': [],
      },
      contentType:
          contentTypes.isNotEmpty ? contentTypes[0] : "application/json",
    ),
    cancelToken: cancelToken,
  )
      .then((response) {
    var serializer = _serializers.serializerForType(Flag);
    var data = _serializers.deserializeWith<Flag>(serializer,
        response.data is String ? jsonDecode(response.data) : response.data);

    return Response<Flag>(
      data: data,
      headers: response.headers,
      request: response.request,
      redirects: response.redirects,
      statusCode: response.statusCode,
      statusMessage: response.statusMessage,
      extra: response.extra,
    );
  });
}