All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dart-dio.api_util.mustache Maven / Gradle / Ivy

There is a newer version: 7.9.0
Show newest version
{{>header}}
import 'dart:convert';

import 'package:built_collection/built_collection.dart';
import 'package:built_value/serializer.dart';

/// Format the given form parameter object into something that Dio can handle.
/// Returns primitive or String.
/// Returns List/Map if the value is BuildList/BuiltMap.
dynamic encodeFormParameter(Serializers serializers, dynamic value, FullType type) {
  if (value == null) {
    return '';
  }
  if (value is String || value is num || value is bool) {
    return value;
  }
  final serialized = serializers.serialize(value, specifiedType: type);
  if (serialized is String) {
    return serialized;
  }
  if (value is BuiltList || value is BuiltMap) {
    return serialized;
  }
  return json.encode(serialized);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy