title: Not able to run web api files in Flutter
body: <p>I am trying to build a login page using flutter and MySQL .I have connected to the dataBase but when  i try running the login.php file I am getting the error &quot;<strong>XMLHttpRequest error</strong>&quot;.I tried downgrading the http to 0.13.2 version but it does not  work .
  Here is the error :-</p>
  <pre><code>Running with sound null safety 
  Debug service listening on ws://127.0.0.1:59586/vPwdx1ozx5U=/ws
  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 908:28                get current
  packages/http/src/browser_client.dart 69:22                                                                                    &lt;fn&gt;
  C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1687:54                                              runUnary
  C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 160:18                                        handleValue
  C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 767:44                                        handleValueCallback
  C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 796:13                                        _propagateToListeners
  C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 593: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 1232:7                                             &lt;fn&gt;
  C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 334: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 339:39  dcall
  C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/html/dart2js/html_dart2js.dart 37332:58                              &lt;fn&gt;
  
  
      at Object.createErrorWithStack (http://localhost:59514/dart_sdk.js:5074:12)
      at Object._rethrow (http://localhost:59514/dart_sdk.js:38925:16)
      at async._AsyncCallbackEntry.new.callback (http://localhost:59514/dart_sdk.js:38921:13)
      at Object._microtaskLoop (http://localhost:59514/dart_sdk.js:38778:13)
      at _startMicrotaskLoop (http://localhost:59514/dart_sdk.js:38784:13)
      at http://localhost:59514/dart_sdk.js:34519:9
  </code></pre>
  <p>Here is my Code for the login page:-</p>
  <pre><code>import 'package:flutter/material.dart';
  import 'mainpg.dart';
  import 'package:http/http.dart' as http;
  import 'dart:convert';
  import 'package:fluttertoast/fluttertoast.dart';
  class login1 extends StatefulWidget {
    const login1({Key? key}) : super(key: key);
  
    @override
    _login1State createState() =&gt; _login1State();
  }
  
  class _login1State extends State&lt;login1&gt; {
    TextEditingController username = TextEditingController();
    TextEditingController password = TextEditingController();
    Future  login() async{
  
      if(username.text == &quot;&quot;||password.text == &quot;&quot;)
        {
          Fluttertoast.showToast(msg: &quot;Both fields cant be blank!&quot;,
              toastLength:Toast.LENGTH_SHORT,
              gravity: ToastGravity.CENTER,
              fontSize: 16.0,
          );
        }
      else{
          var url =Uri.parse('http://localhost/localconnect/login.php');
          var response = await http.post(url,headers: &lt;String, String&gt;{
            'Content-Type': 'application/json; charset=UTF-8',
          },
              body:jsonEncode(&lt;String, String&gt;{
          &quot;username&quot;:username.text,
          &quot;password&quot;:password.text,
          }),);
          var data = json.decode(response.body);
          if(data == &quot;success&quot;){
          Navigator.push(context,MaterialPageRoute(builder:(context){
          return const mainpage();
          }));
          }
          else{
          Fluttertoast.showToast(msg: &quot;The user and Password combination does not exist!&quot;,
          toastLength:Toast.LENGTH_SHORT,
          gravity: ToastGravity.CENTER,
          fontSize: 16.0,
          );
          }
      }
    }
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        backgroundColor: Colors.white,
        body:SafeArea(
          child: Row(
              crossAxisAlignment:CrossAxisAlignment.start,
              children:[
                Expanded(
                  flex:2,
                  child: Container(
                      width:1,
                      color:Colors.white,
                      child:Column(
                        mainAxisAlignment: MainAxisAlignment.start,
                        children:   [
                          const Image(
                            image: AssetImage('image/foodexpress2.jpg'),
                          ),
                          const SizedBox(height:5),
                          const Text(
                              'Food Express',
                              textDirection: TextDirection.ltr,
                              style:TextStyle(
                                decoration: TextDecoration.none,
                                fontSize:40,
                                color:Colors.red,
                                fontFamily: 'Roboto',
                                fontWeight:FontWeight.w700,
                              )
                          ),
                          const SizedBox(height:30),
                          Expanded(
                            child: Container(
                              color:Colors.grey[200],
                              child: Column(
                                children:  [
                                  const Padding(
                                    padding: EdgeInsets.all(20.0),
                                    child: Text(
                                        'Login',
                                        textDirection: TextDirection.ltr,
                                        style:TextStyle(
                                          decoration: TextDecoration.none,
                                          fontSize:25,
                                          fontFamily: 'Roboto',
                                          color:Colors.redAccent,
                                          fontWeight:FontWeight.w700,
                                        )
                                    ),
                                  ),
                                   Padding(
                                    padding: const EdgeInsets.only(left:25.0,right:25.0),
                                    child: TextField(
                                      controller: username,
                                      autofocus: true,
                                    //  onChanged:(value){
                                        //Username= value;
                                      //  print(Username);
                                    //  },
                                      textAlign: TextAlign.center,
                                      cursorColor: Color(0xFFC41A38),
                                      textInputAction: TextInputAction.next,
                                      keyboardType: TextInputType.emailAddress,
                                      decoration: const InputDecoration(
                                        hintText:'Enter username',
                                        hintStyle: TextStyle(
                                          fontStyle:FontStyle.italic,
                                          color:Color(0xFF1B1F32),
                                        ),
                                        contentPadding:
                                        EdgeInsets.symmetric(vertical: 10.0, horizontal: 20.0),
                                        border: OutlineInputBorder(
                                          borderRadius: BorderRadius.all(Radius.circular(32.0)),
                                        ),
                                        enabledBorder: OutlineInputBorder(
                                          borderSide: BorderSide(color: Colors.blueAccent, width: 1.0),
                                          borderRadius: BorderRadius.all(Radius.circular(32.0)),
                                        ),
                                        focusedBorder: OutlineInputBorder(
                                          borderSide: BorderSide(color: Colors.blueAccent, width: 2.0),
                                          borderRadius: BorderRadius.all(Radius.circular(32.0)),
                                        ),
                                      ),
                                    ),
                                  ),
                                  const SizedBox(height:20),
                                    Padding(
                                    padding: const EdgeInsets.only(left:25.0,right:25.0),
                                    child: TextField(
                                      controller:password,
                                      //onChanged:(value){
                                       // Password = value;
                                      //  print(Password);
                                    //  },
                                      autofocus:true,
                                      textAlign: TextAlign.center,
                                      obscureText: true,
                                      cursorColor: const Color(0xFFC41A38),
                                      textInputAction: TextInputAction.next,
                                      keyboardType: TextInputType.emailAddress,
                                      decoration: const InputDecoration(
  
                                        hintText:'Enter Password',
                                        hintStyle: TextStyle(
                                          fontStyle:FontStyle.italic,
                                          color:Color(0xFF1B1F32),
                                        ),
                                        contentPadding:
                                        EdgeInsets.symmetric(vertical: 10.0, horizontal: 20.0),
                                        border: OutlineInputBorder(
                                          borderRadius: BorderRadius.all(Radius.circular(32.0)),
                                        ),
                                        enabledBorder: OutlineInputBorder(
                                          borderSide: BorderSide(color: Colors.blueAccent, width: 1.0),
                                          borderRadius: BorderRadius.all(Radius.circular(32.0)),
                                        ),
                                        focusedBorder: OutlineInputBorder(
                                          borderSide: BorderSide(color: Colors.blueAccent, width: 2.0),
                                          borderRadius: BorderRadius.all(Radius.circular(32.0)),
                                        ),
                                      ),
                                    ),
                                  ),
                                  const SizedBox(height:20),
                                  Material(
                                      elevation:5.0,
                                      color:Colors.blueAccent,
                                      borderRadius:BorderRadius.circular(30.0),
                                      child:MaterialButton(
                                          onPressed:(){
                                            setState((){
                                              login();
                                            });
                                          },
                                          minWidth:620,
                                          height:60.0,
                                          child:const Text(
                                            'Log In',
                                            style: TextStyle(
                                              color: Colors.white,
                                            ),
                                          ),
                                  ),
                                  ),
                                ],
                              ),
                            ),
                          ),
                        ],
                      )
                  ),
                ),
                Expanded(
                  flex:2,
                  child: Container(
                    width: 1,
                    decoration:  const BoxDecoration(
                        image:  DecorationImage(
                          image:  AssetImage('image/food1.jpg'),
                          fit: BoxFit.fill,
                        )
                    ),
                  ),
                ),
              ]
          ),
        ),
      );
    }
  
  }
  </code></pre>