Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connection closed while receiving data(image through NetworkImage) flutter while retriving data from localhost

While retrieving the image file from network http://10.0.2.2:8000 localhost I got the following error:
Connection closed while receiving data.

I have an error when I call data (images only) from the URL.
Note that I am using a local server.
I’m trying to put the image inside Image.network(), this is image code.

Image.network(urllink)

The same URL works properly in the localhost browser and postman also.
I am trying to retrieve images in the decoration box widget.
The same url and image work when I paste direct url in the network image function but an error occurred when I tried to fetch the photoname through the apis. The photoname and APIs I am getting are working fine. There is not any problem with it.

 child: FutureBuilder<MatrimonyProfileData>(
                  future: futureMData,
                  builder: (context, snapshot) {
                    if (snapshot.hasData) {
                      // String matrimonyUrl = '/$matrimonyprofileUrl';
                      String photoName = snapshot.data!.matrimonies.photo;

                      print(photoName);
                      //var fullUrl = _url + apiUrl

                      var url;
                      // urllink = 'http://10.0.2.2:8000/matrimony/profile.jpg';

                      **url = (webLink + matrimony + photoName);
                      print(url);
                      String urllink = Url;**
                      return Column(
                        children: [
                          Container(
                            color: Colors.deepPurpleAccent.shade100,
                            child: Column(
                              children: <Widget>[
                                Container(
                                  margin: const EdgeInsets.all(15.0),
                                  padding: const EdgeInsets.all(3.0),
                                  decoration: BoxDecoration(
                                      border: Border.all(
                                          color: Colors.black, width: 3)),
                                  child: Wrap(
                                    // mainAxisAlignment: MainAxisAlignment.end,
                                    // direction: Axis.vertical,
                                    children: <Widget>[
                                      
                                Container(
                                  height: 300,
                                  width: 400,
                                  //color: Colors.amber,
                                  child: Row(
                                    children: <Widget>[
                                      Container(
                                          height: 300,
                                          width: 170,
                                          //color: Colors.amber,
                                          decoration: BoxDecoration(
                                            image: DecorationImage(
                                                image: **NetworkImage(urllink),**

                                                
                                                fit: BoxFit.fitWidth),
                                            
                                          )),
                                      // SizedBox(
                                      //   width: 20,
                                      // ),

same problem on this link also https://askandroidquestions.com/2021/07/12/flutter-exception-connection-closed-while-receiving-data/

like image 226
Purvekta Avatar asked Aug 11 '26 10:08

Purvekta


1 Answers

You might be missing Keep-Alive header in your http request.

Try adding this to your request headers:

  "Connection": "Keep-Alive",
like image 128
Muhammad Hussain Avatar answered Aug 14 '26 17:08

Muhammad Hussain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!