You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I really love your package, however, I came across an issue where I wanted to pass a QueryMap as an optional/nullable value and this resulted in it simply being added to the list of $param using $params.addAll(theNullableQueryMap). This however fails, because a nullable value can not be added to a Map using Map.addAll.
@overrideFuture<Response<List<Article>>> getArticles(
{String? articleId,
String? authorName,
int? limit =10,
Map<String, dynamic>? filters}) {
final $url ='articles';
final $params =<String, dynamic>{
'article_id': articleId,
'authorName': authorName,
'limit': limit
};
$params.addAll(filters); // <-- this here will fail to compile because `filters` can't be nullable final $request =Request('GET', $url, client.baseUrl, parameters: $params);
return client.send<List<Article>, Article>($request);
}
It throws this compilation error:
Error: The argument type 'Map<String, dynamic>?' can't be assigned to the parameter type 'Map<String, dynamic>' because 'Map<String, dynamic>?' is nullable and 'Map<String, dynamic>' isn't.
- 'Map' is from 'dart:core'.
$params.addAll(filters);
^
I would propose it checks if filters is null before using $params.addAll
final $params =<String, dynamic>{
'article_id': articleId,
'authorName': authorName,
'limit': limit
};
if (filters !=null) {
$params.addAll(filters);
}
Hi, I really love your package, however, I came across an issue where I wanted to pass a
QueryMap
as an optional/nullable value and this resulted in it simply being added to the list of$param
using$params.addAll(theNullableQueryMap)
. This however fails, because a nullable value can not be added to aMap
usingMap.addAll
.Essentially this:
results in
It throws this compilation error:
I would propose it checks if
filters
isnull
before using$params.addAll
or simply using something more elegant like:
The text was updated successfully, but these errors were encountered: