post method Null safety

  1. @override
Future<Map<String, dynamic>> post(
  1. {dynamic data,
  2. String partOfUrl = '',
  3. String? apiUserToken}
)
override

Implementation

@override
Future<Map<String, dynamic>> post({
  dynamic data,
  String partOfUrl = '',
  String? apiUserToken,
}) async {
  Dio _dio = dio;
  Map<String, dynamic> queryParameters = dio.options.queryParameters.map((key, value) => MapEntry(key, value));

  if (apiUserToken?.isNotEmpty ?? false) {
    if (queryParameters.containsKey("api_token")) {
      _dio = copyDio(dio.options);

      queryParameters.remove('api_token');
      queryParameters.addAll({
        'api_token': apiUserToken
      });
    }

    _dio.options.queryParameters = queryParameters;
  }

  var url = "$baseURI";

  if (partOfUrl.isNotEmpty) {
    url += '$partOfUrl';
  }

  try {
    var result = await _dio.post(url, data: data);
    return result.data is String ? json.decode(result.data) : result.data;
  } on DioError catch (e) {
    print(e.response);
    rethrow;
  }
}