The argument type ‘Object?’ can’t be assigned to the parameter type ‘Widget?

Posted by


The argument type 'Object' can't be assigned to the parameter type 'String'.dartargument_type_not_assignable Object pvalue Type: Object


When concatenating pvalue to a string, an error message is displayed indicating that there is a mismatch in type. Although it is assumed that the pvalue variable is of type Object, it must first be explicitly cast to the String type in order to be utilised in string concatenation.

To resolve this error, you can cast pvalue to a String when constructing the URL:

var url = Uri.parse(baseURL + 'quotes/closed/' + pvalue.toString());

This guarantees that when creating the URL, pvalue is handled as a String. To prevent runtime issues, you should handle the null situation appropriately if pvalue has the potential to be null. As an illustration:

var url = Uri.parse(baseURL + 'quotes/closed/' + (pvalue != null ? pvalue.toString() : ''));

This way, if pvalue is null, an empty string is used in the URL, preventing the type mismatch error.

Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x