'Keycloak gives me XMLHttpRequest error. with flutter but don't with postman

Goodmorning, I'm trying to use keycloak and flutter but unfortunally when i ask the token to keycloak he gives me an XMLHttpRequestError. I use thos method to ask:

Future<String> makeTokenRequest(String url,Map<String,String>params) async {
        try {
          print("arrivato in _restManager");
          await post(url, body: params).then((result) {
            print(result.toString());
          });
        }catch(e){
           throw e;
        }
      }

 Future<String> getToken(String email,String password) async {
    try{
      Map<String,String> params=Map();
      params["grant_type"]="password";
      params["client_id"]="myclient";
      params["client_secret"]="6be8e24b-9c81-482e-99ac-05ed154e572e";
      params["username"]="cappuccio";
      params["password"]="franco";
      String result=await _restManager.makeTokenRequest("http://localhost:8080/auth/realms/PiattaformaPrenotazioni/protocol/openid-connect/token",params);
    }catch(e){
      throw e;
    }
  }

those two methods are just toys that i'm using to learn, i know that probably they aren't the best way. I read that if i don't specify anything post method will use urlencoded and with a Map<String,String> body he will encode it right. The Error i get is this:

Error: XMLHttpRequest error.
    C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 909:28                get current
packages/http/src/browser_client.dart 84:22                                                                                    <fn>
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1613:54                                              runUnary
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 155:18                                        handleValue
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 707:44                                        handleValueCallback
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 736:13                                        _propagateToListeners
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 533:7                                         [_complete]
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream_pipe.dart 61:11                                         _cancelAndValue
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream.dart 1219:7                                             <fn>
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 324:14  _checkAndCall
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 329:39  dcall
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/html/dart2js/html_dart2js.dart 37307:58                              <fn>


    at Object.createErrorWithStack (http://localhost:57146/dart_sdk.js:5362:12)
    at Object._rethrow (http://localhost:57146/dart_sdk.js:39548:16)
    at async._AsyncCallbackEntry.new.callback (http://localhost:57146/dart_sdk.js:39542:13)
    at Object._microtaskLoop (http://localhost:57146/dart_sdk.js:39374:13)
    at _startMicrotaskLoop (http://localhost:57146/dart_sdk.js:39380:13)
    at http://localhost:57146/dart_sdk.js:34887:9
arrivato in _restManager
errore in restManager
errore in SharedInstance
Error: XMLHttpRequest error.
    C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 909:28                get current
packages/http/src/browser_client.dart 84:22                                                                                    <fn>
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1613:54                                              runUnary
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 155:18                                        handleValue
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 707:44                                        handleValueCallback
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 736:13                                        _propagateToListeners
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 533:7                                         [_complete]
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream_pipe.dart 61:11                                         _cancelAndValue
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/stream.dart 1219:7                                             <fn>
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 324:14  _checkAndCall
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 329:39  dcall
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/html/dart2js/html_dart2js.dart 37307:58                              <fn>


    at Object.createErrorWithStack (http://localhost:57146/dart_sdk.js:5362:12)
    at Object._rethrow (http://localhost:57146/dart_sdk.js:39548:16)
    at async._AsyncCallbackEntry.new.callback (http://localhost:57146/dart_sdk.js:39542:13)
    at Object._microtaskLoop (http://localhost:57146/dart_sdk.js:39374:13)
    at _startMicrotaskLoop (http://localhost:57146/dart_sdk.js:39380:13)
    at http://localhost:57146/dart_sdk.js:34887:9


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source