Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

type 'Null' is not a subtype of type 'String' in type cast #644

Closed
ielb opened this issue Dec 1, 2021 · 1 comment
Closed

type 'Null' is not a subtype of type 'String' in type cast #644

ielb opened this issue Dec 1, 2021 · 1 comment

Comments

@ielb
Copy link

ielb commented Dec 1, 2021

Getting this error when using a post method
this is TrackTrace : #0 CastMap.forEach. (dart:_internal/cast.dart:288:25)
#1 _LinkedHashMapMixin.forEach (dart:collection-patch/compact_hash.dart:400:8)
#2 CastMap.forEach (dart:_internal/cast.dart:287:13)
#3 mapToQuery (package:http/src/utils.dart:17:7)
#4 Request.bodyFields= (package:http/src/request.dart:137:12)
#5 BaseClient._sendUnstreamed (package:http/src/base_client.dart:87:17)
#6 BaseClient.post (package:http/src/base_client.dart:32:7)
#7 post. (package:http/http.dart:69:16)
#8 _withClient (package:http/http.dart:164:20)
#9 post (package:http/http.dart:68:5)
#10 Api.httpPost (package:knorrieplay/services/api.dart:33:14)
#11 UserService.addUser (package:knorrieplay/services/user_service.dart:8:18)
#12 AuthProvider.signInWithFacebook (package:knorrieplay/providers/auth_provider.dart:219:23)

#13 _LoginPageState.facebookAuth (package:knorrieplay/pages/login_page.dart:89:18)

the method i used
Future<http.Response?> httpPost(String endPath, Object body) async {
try {
Uri uri = Uri.parse('$url$endPath');
return http.post(uri, body: body, headers: headers);
} catch (e) {
print(e);
}
}

::::::::::: when i use dio it works fine

@natebosch
Copy link
Member

natebosch commented Dec 17, 2021

The doc comment on http.post says:

body sets the body of the request. It can be a String, a List<int> or a Map<String, String>.

You have passed a Map which contains a value that is null, which is not a String.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants